Skip to contentSkip to conversation

mm: cma: add a simple kernel module as the helper to test CMA

PATCH RESEND In review Barry Song 3 participants 3 messages Jul 5, 2012

lore
Share & tools
lore

Barry Song

author
#0 lore raw

PATCH RESEND v4 1/1 mm: cma: add a simple kernel module as the helper to test CMA

From: Barry Song <[email protected]>

Any write request to /dev/cma_test will let the module to allocate memory from CMA, for example:

1st time

$ echo 1024 > /dev/cma_test
will require cma_test to request 1MB(1024KB)
2nd time
$ echo 2048 > /dev/cma_test
will require cma_test to request 2MB(2048KB)

Any read request to /dev/cma_test will let the module to free the 1st valid memory from CMA, for example:

1st time

$ cat /dev/cma_test
will require cma_test to free the 1MB allocated in the first write request
2nd time
$ cat /dev/cma_test
will require cma_test to free the 2MB allocated in the second write request
Cc Marek Szyprowski <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---
resend to Greg KH so that he can decide whether it should be placed at tools or drivers/misc;
See the discussion thread:
[1] https://lkml.org/lkml/2012/7/3/80
[2] https://lkml.org/lkml/2012/7/3/224
[3] https://lkml.org/lkml/2012/7/4/87

 tools/cma/Makefile   |   13 +++++
 tools/cma/cma_test.c |  140 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 0 deletions(-)
 create mode 100644 tools/cma/Makefile
 create mode 100644 tools/cma/cma_test.c
tools/cma/Makefile new file +13 -0
new file mode 100644
index 0000000..d15c2c0
@@ -0,0 +1,13 @@
+# Kernel modules
+#
+# To compile for ARM:
+# make ARCH=arm CC=arm-none-linux-gnueabi-gcc
+#
+obj-m	+= cma_test.o
+
+build: kernel_modules
+
+kernel_modules:
+	${MAKE} -C $(CURDIR)/../.. M=$(CURDIR)
+clean:
+	${MAKE} -C $(CURDIR)/../.. M=$(CURDIR) clean
tools/cma/cma_test.c new file +140 -0

140 lines not on this page · raw message

Signature · 6 lines
1.7.1



Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog
#1 lore raw
Quoted 15 lines · Barry Song

From: Barry Song <[email protected]>

Any write request to /dev/cma_test will let the module to allocate memory from CMA, for example:

1st time

$ echo 1024 > /dev/cma_test
will require cma_test to request 1MB(1024KB)
2nd time
$ echo 2048 > /dev/cma_test
will require cma_test to request 2MB(2048KB)

Any read request to /dev/cma_test will let the module to free the 1st valid memory from CMA, for example:

Quoted 6 lines

1st time

$ cat /dev/cma_test
will require cma_test to free the 1MB allocated in the first write request
2nd time
$ cat /dev/cma_test
will require cma_test to free the 2MB allocated in the second write request

I missed the earlier times this was posted and read up on it now.

Quoted 11 lines
Cc Marek Szyprowski <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---
resend to Greg KH so that he can decide whether it should be placed at tools or drivers/misc;
See the discussion thread:
[1] https://lkml.org/lkml/2012/7/3/80
[2] https://lkml.org/lkml/2012/7/3/224
[3] https://lkml.org/lkml/2012/7/4/87

I think it should be in mm/cma-test.c, along with kmemleak-test.c. It would be nice if you could add some code that just runs at boot time (or when the module is loaded) and allocates and frees memory using CMA.

Quoted 1 line

+static struct device *cma_dev;

Do you actually need this device? It's not connected to hardware so it doesn't actually do DMA and we might as well pass a NULL pointer into dma_alloc_*().

Quoted 4 lines
tools/cma/cma_test.c new file +4 -0
+static const struct file_operations cma_test_fops = {
+	.owner =    THIS_MODULE,
+	.read  =    cma_test_read,
+	.write =    cma_test_write,

tools/cma/cma_test.c line 117

Quoted 10 lines
tools/cma/cma_test.c new file +10 -0
+};
+
+static struct miscdevice cma_test_misc = {
+	.name = "cma_test",
+	.fops = &cma_test_fops,
+};
+
+static int __init cma_test_init(void)
+{
+	int ret = misc_register(&cma_test_misc);

A better place for this is really debugfs. The driver is not meant as a stable kernel interface that applications can rely on, it's purely a debugging help.

Just make this

	ret = debugfs_create_file("cma-test", 0600, NULL, NULL, &cma_test_fops);



	Arnd
#2 lore raw

Hi Arnd,

2012/7/5 Arnd Bergmann <[email protected]>:

Quoted 29 lines

I think it should be in mm/cma-test.c, along with kmemleak-test.c. It would be nice if you could add some code that just runs at boot time (or when the module is loaded) and allocates and frees memory using CMA.

Quoted 1 line

+static struct device *cma_dev;

Do you actually need this device? It's not connected to hardware so it doesn't actually do DMA and we might as well pass a NULL pointer into dma_alloc_*().

Quoted 4 lines
tools/cma/cma_test.c new file +4 -0
+static const struct file_operations cma_test_fops = {
+     .owner =    THIS_MODULE,
+     .read  =    cma_test_read,
+     .write =    cma_test_write,

tools/cma/cma_test.c line 117

Quoted 10 lines
tools/cma/cma_test.c new file +10 -0
+};
+
+static struct miscdevice cma_test_misc = {
+     .name = "cma_test",
+     .fops = &cma_test_fops,
+};
+
+static int __init cma_test_init(void)
+{
+     int ret = misc_register(&cma_test_misc);

A better place for this is really debugfs. The driver is not meant as a stable kernel interface that applications can rely on, it's purely a debugging help.

Quoted 4 lines

Just make this

        ret = debugfs_create_file("cma-test", 0600, NULL, NULL, &cma_test_fops);

we did have some discussions about this at:
http://www.spinics.net/lists/arm-kernel/msg163548.html

i'd say both are acceptable to me.

Quoted 2 lines

Arnd

-barry