Change coresight tmc from misc device to cdev device
RFC PATCH 1/1 Change coresight tmc from misc device to cdev device
For coresight in the server scenario, if there are too many cpu cores and too many tmc peripherals, the error of insufficient device numbers will occur by misc device
--- drivers/hwtracing/coresight/coresight-core.c | 53 +++++++++++++++++++ .../hwtracing/coresight/coresight-tmc-core.c | 13 ++--- drivers/hwtracing/coresight/coresight-tmc.h | 4 +- include/linux/coresight.h | 23 ++++++++ 4 files changed, 83 insertions(+), 10 deletions(-)
drivers/hwtracing/coresight/coresight-core.c +53 -0
@@ -17,6 +17,7 @@#include <linux/coresight.h> #include <linux/of_platform.h> #include <linux/delay.h> +#include <linux/cdev.h> #include <linux/pm_runtime.h> #include "coresight-etm-perf.h"
@@ -1567,6 +1568,58 @@ void coresight_release_platform_data(struct coresight_device *csdev,coresight_remove_conns_sysfs_group (csdev); } +int coresight_cdev_register (struct coresight_cdev *cdev,const struct file_operations *fops, +const char *name) +{ +struct device *device; + +if (alloc_chrdev_region (&cdev->devno,0 ,1 , name)) { +pr_err ("failed to create the coresight cdev region\n" ); +return -EFAULT ; + } + + cdev->class =class_create (THIS_MODULE , name); +if (IS_ERR (cdev->class)) { +pr_err ("failed to create the coresight class\n" ); + goto coresight_unregister_region; + } + +cdev_init (&cdev->cdev, fops); +if (cdev_add (&cdev->cdev, cdev->devno,1 )) { +pr_err ("failed to add the coresight cdev\n" ); + goto coresight_free_class; + } + + device =device_create (cdev->class,NULL , cdev->devno, + cdev, name); +if (IS_ERR (device)) { +pr_err ("failed to create device for coresight\n" ); + goto coresight_del_cdev; + } + +return 0 ; + +coresight_del_cdev: +cdev_del (&cdev->cdev); +coresight_free_class: +class_destroy (cdev->class); +coresight_unregister_region: +unregister_chrdev_region (cdev->devno,1 ); + +return -EFAULT ; +} +EXPORT_SYMBOL_GPL (coresight_cdev_register); + +int coresight_cdev_unregister (struct coresight_cdev *cdev) +{ +device_destroy (cdev->class, cdev->devno); +cdev_del (&cdev->cdev); +class_destroy (cdev->class); +unregister_chrdev_region (cdev->devno,1 ); +return 0 ; +} +EXPORT_SYMBOL_GPL (coresight_cdev_unregister); +struct coresight_device *coresight_register (struct coresight_desc *desc) {int ret;
drivers/hwtracing/coresight/coresight-tmc-core.c +5 -8
@@ -147,7 +147,7 @@ static int tmc_open(struct inode *inode, struct file *file) {int ret;struct tmc_drvdata *drvdata =container_of (file->private_data, - struct tmc_drvdata, miscdev); + struct tmc_drvdata, cdev); ret =tmc_read_prepare (drvdata);if (ret)
@@ -179,7 +179,7 @@ static ssize_t tmc_read(struct file *file, char __user *data, size_t len,char *bufp;ssize_t actual;struct tmc_drvdata *drvdata =container_of (file->private_data, - struct tmc_drvdata, miscdev); + struct tmc_drvdata, cdev); actual =tmc_get_sysfs_trace (drvdata, *ppos, len, &bufp);if (actual <=0 )return 0 ;
@@ -200,7 +200,7 @@ static int tmc_release(struct inode *inode, struct file *file) {int ret;struct tmc_drvdata *drvdata =container_of (file->private_data, - struct tmc_drvdata, miscdev); + struct tmc_drvdata, cdev); ret =tmc_read_unprepare (drvdata);if (ret)
@@ -529,10 +529,7 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) goto out; } - drvdata->miscdev.name = desc.name; - drvdata->miscdev.minor =MISC_DYNAMIC_MINOR ; - drvdata->miscdev.fops = &tmc_fops; - ret =misc_register (&drvdata->miscdev); + ret =coresight_cdev_register (&drvdata->cdev, &tmc_fops, desc.name);if (ret)coresight_unregister (drvdata->csdev);else
@@ -572,7 +569,7 @@ static void tmc_remove(struct amba_device *adev)* etb fops in this case, device is there until last file * handler to this device is closed. */ -misc_deregister (&drvdata->miscdev); +coresight_cdev_unregister (&drvdata->cdev);coresight_unregister (drvdata->csdev); }
drivers/hwtracing/coresight/coresight-tmc.h +2 -2
@@ -166,7 +166,7 @@ struct etr_buf {* struct tmc_drvdata - specifics associated to an TMC component * @base: memory mapped base address for this component. * @csdev: component vitals needed by the framework. -* @miscdev: specifics to handle "/dev/xyz.tmc" entry. +* @cdev: specifics to handle "/dev/xyz.tmc" entry. * @spinlock: only one at a time pls. * @pid: Process ID of the process being monitored by the session * that is using this component.
@@ -188,7 +188,7 @@ struct etr_buf {struct tmc_drvdata {void __iomem *base;struct coresight_device *csdev; -struct miscdevice miscdev; +struct coresight_cdev cdev;spinlock_t spinlock;pid_t pid;bool reading;
include/linux/coresight.h +23 -0
@@ -9,6 +9,7 @@#include <linux/device.h> #include <linux/io.h> #include <linux/perf_event.h> +#include <linux/cdev.h> #include <linux/sched.h> /* Peripheral id registers (0xFD0-0xFEC) */
@@ -252,6 +253,12 @@ struct coresight_device {void *active_cscfg_ctxt; }; +struct coresight_cdev { +dev_t devno; +struct class *class; +struct cdev cdev; +}; +/* * coresight_dev_list - Mapping for devices to "name" index for device * names.
@@ -506,6 +513,10 @@ void coresight_relaxed_write64(struct coresight_device *csdev, u64 val, u32 offset);void coresight_write64 (struct coresight_device *csdev,u64 val,u32 offset); +int coresight_cdev_register (struct coresight_cdev *cdev,const struct file_operations *fops, +const char *name); + +int coresight_cdev_unregister (struct coresight_cdev *cdev);#else static inline struct coresight_device *coresight_register (struct coresight_desc *desc) {return NULL ; }
@@ -581,6 +592,18 @@ static inline void coresight_write64(struct coresight_device *csdev, u64 val, u3 { } +static inline int coresight_cdev_register (struct coresight_cdev *cdev, +const struct file_operations *fops, +const char *name) +{ +return 0 ; +} + +static inline int coresight_cdev_unregister (struct coresight_cdev *cdev) +{ +return 0 ; +} +#endif /* IS_ENABLED(CONFIG_CORESIGHT) */ extern int coresight_get_cpu (struct device *dev);
Signature · 7 lines
2.27.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi Jay,
Quoted 4 lines · Jay Chen
For coresight in the server scenario, if there are too many cpu cores and too many tmc peripherals, the error of insufficient device numbers will occur by misc device
There really is more than 128 miscdevice allocated in your system? How may TMC do you have?
Quoted 29 lines
Signed-off-by Jay Chen <[email protected]>--- drivers/hwtracing/coresight/coresight-core.c | 53 +++++++++++++++++++ .../hwtracing/coresight/coresight-tmc-core.c | 13 ++--- drivers/hwtracing/coresight/coresight-tmc.h | 4 +- include/linux/coresight.h | 23 ++++++++ 4 files changed, 83 insertions(+), 10 deletions(-)drivers/hwtracing/coresight/coresight-core.c +6
-0@@ -17,6 +17,7 @@#include <linux/coresight.h> #include <linux/of_platform.h> #include <linux/delay.h> +#include <linux/cdev.h> #include <linux/pm_runtime.h> #include "coresight-etm-perf.h" @@ -1567,6 +1568,58 @@ void coresight_release_platform_data(struct coresight_device *csdev,coresight_remove_conns_sysfs_group (csdev); } +int coresight_cdev_register (struct coresight_cdev *cdev,const struct file_operations *fops, +const char *name) +{ +struct device *device; +
drivers/hwtracing/coresight/coresight-core.c void coresight_release_platform_data(struct coresight_device *csdev, · line 1585
Quoted 10 lines
drivers/hwtracing/coresight/coresight-core.c +10
-0+if (alloc_chrdev_region (&cdev->devno,0 ,1 , name)) { +pr_err ("failed to create the coresight cdev region\n" ); +return -EFAULT ; + } + + cdev->class =class_create (THIS_MODULE , name); +if (IS_ERR (cdev->class)) { +pr_err ("failed to create the coresight class\n" ); + goto coresight_unregister_region; + }
From the above a new class is created for every TMC, even if they are all the same. A better way to do this would be to create a single TMC class with a new cdev for every new TMC.
To do this alloc_chrdev_region() and class_create() have to be called when the module is added to the system. Have a look at funnel_init() on how to refactor the TMC core driver with an init function and rpmsg_chrdev_init() for the chrdev region allocation and the class creation.
From there every time a TMC is probe cdev_init() and cdev_add() can be called - look at rpmsg_chrdev_probe() for an example. Instead of using an IDA to pick out a minor number you should be able to use dev_list->nr_idx - 1.
Thanks,
Mathieu
Quoted 172 lines
drivers/hwtracing/coresight/coresight-core.c +37
-0+ +cdev_init (&cdev->cdev, fops); +if (cdev_add (&cdev->cdev, cdev->devno,1 )) { +pr_err ("failed to add the coresight cdev\n" ); + goto coresight_free_class; + } + + device =device_create (cdev->class,NULL , cdev->devno, + cdev, name); +if (IS_ERR (device)) { +pr_err ("failed to create device for coresight\n" ); + goto coresight_del_cdev; + } + +return 0 ; + +coresight_del_cdev: +cdev_del (&cdev->cdev); +coresight_free_class: +class_destroy (cdev->class); +coresight_unregister_region: +unregister_chrdev_region (cdev->devno,1 ); + +return -EFAULT ; +} +EXPORT_SYMBOL_GPL (coresight_cdev_register); + +int coresight_cdev_unregister (struct coresight_cdev *cdev) +{ +device_destroy (cdev->class, cdev->devno); +cdev_del (&cdev->cdev); +class_destroy (cdev->class); +unregister_chrdev_region (cdev->devno,1 ); +return 0 ; +} +EXPORT_SYMBOL_GPL (coresight_cdev_unregister); +struct coresight_device *coresight_register (struct coresight_desc *desc) {int ret;drivers/hwtracing/coresight/coresight-tmc-core.c +5
-8@@ -147,7 +147,7 @@ static int tmc_open(struct inode *inode, struct file *file) {int ret;struct tmc_drvdata *drvdata =container_of (file->private_data, - struct tmc_drvdata, miscdev); + struct tmc_drvdata, cdev); ret =tmc_read_prepare (drvdata);if (ret)@@ -179,7 +179,7 @@ static ssize_t tmc_read(struct file *file, char __user *data, size_t len,char *bufp;ssize_t actual;struct tmc_drvdata *drvdata =container_of (file->private_data, - struct tmc_drvdata, miscdev); + struct tmc_drvdata, cdev); actual =tmc_get_sysfs_trace (drvdata, *ppos, len, &bufp);if (actual <=0 )return 0 ;@@ -200,7 +200,7 @@ static int tmc_release(struct inode *inode, struct file *file) {int ret;struct tmc_drvdata *drvdata =container_of (file->private_data, - struct tmc_drvdata, miscdev); + struct tmc_drvdata, cdev); ret =tmc_read_unprepare (drvdata);if (ret)@@ -529,10 +529,7 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) goto out; } - drvdata->miscdev.name = desc.name; - drvdata->miscdev.minor =MISC_DYNAMIC_MINOR ; - drvdata->miscdev.fops = &tmc_fops; - ret =misc_register (&drvdata->miscdev); + ret =coresight_cdev_register (&drvdata->cdev, &tmc_fops, desc.name);if (ret)coresight_unregister (drvdata->csdev);else @@ -572,7 +569,7 @@ static void tmc_remove(struct amba_device *adev)* etb fops in this case, device is there until last file * handler to this device is closed. */ -misc_deregister (&drvdata->miscdev); +coresight_cdev_unregister (&drvdata->cdev);coresight_unregister (drvdata->csdev); }drivers/hwtracing/coresight/coresight-tmc.h +2
-2@@ -166,7 +166,7 @@ struct etr_buf {* struct tmc_drvdata - specifics associated to an TMC component * @base: memory mapped base address for this component. * @csdev: component vitals needed by the framework. -* @miscdev: specifics to handle "/dev/xyz.tmc" entry. +* @cdev: specifics to handle "/dev/xyz.tmc" entry. * @spinlock: only one at a time pls. * @pid: Process ID of the process being monitored by the session * that is using this component. @@ -188,7 +188,7 @@ struct etr_buf {struct tmc_drvdata {void __iomem *base;struct coresight_device *csdev; -struct miscdevice miscdev; +struct coresight_cdev cdev;spinlock_t spinlock;pid_t pid;bool reading;include/linux/coresight.h +23
-0@@ -9,6 +9,7 @@#include <linux/device.h> #include <linux/io.h> #include <linux/perf_event.h> +#include <linux/cdev.h> #include <linux/sched.h> /* Peripheral id registers (0xFD0-0xFEC) */ @@ -252,6 +253,12 @@ struct coresight_device {void *active_cscfg_ctxt; }; +struct coresight_cdev { +dev_t devno; +struct class *class; +struct cdev cdev; +}; +/* * coresight_dev_list - Mapping for devices to "name" index for device * names. @@ -506,6 +513,10 @@ void coresight_relaxed_write64(struct coresight_device *csdev, u64 val, u32 offset);void coresight_write64 (struct coresight_device *csdev,u64 val,u32 offset); +int coresight_cdev_register (struct coresight_cdev *cdev,const struct file_operations *fops, +const char *name); + +int coresight_cdev_unregister (struct coresight_cdev *cdev);#else static inline struct coresight_device *coresight_register (struct coresight_desc *desc) {return NULL ; }@@ -581,6 +592,18 @@ static inline void coresight_write64(struct coresight_device *csdev, u64 val, u3 { } +static inline int coresight_cdev_register (struct coresight_cdev *cdev, +const struct file_operations *fops, +const char *name) +{ +return 0 ; +} + +static inline int coresight_cdev_unregister (struct coresight_cdev *cdev) +{ +return 0 ; +} +#endif /* IS_ENABLED(CONFIG_CORESIGHT) */ extern int coresight_get_cpu (struct device *dev);Signature · 1 line
2.27.0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi Mathieu
Thank you for your reply,firstly.
Quoted 9 lines · Mathieu Poirier
Hi Jay,
Quoted 4 lines · Jay Chen
For coresight in the server scenario, if there are too many cpu cores and too many tmc peripherals, the error of insufficient device numbers will occur by misc device
There really is more than 128 miscdevice allocated in your system? How may TMC do you have?
There are 128 TMCs on our system.
Quoted 49 lines
Quoted 30 lines
Signed-off-by Jay Chen <[email protected]>--- drivers/hwtracing/coresight/coresight-core.c | 53 +++++++++++++++++++ .../hwtracing/coresight/coresight-tmc-core.c | 13 ++--- drivers/hwtracing/coresight/coresight-tmc.h | 4 +- include/linux/coresight.h | 23 ++++++++ 4 files changed, 83 insertions(+), 10 deletions(-)drivers/hwtracing/coresight/coresight-core.c +6
-0@@ -17,6 +17,7 @@#include <linux/coresight.h> #include <linux/of_platform.h> #include <linux/delay.h> +#include <linux/cdev.h> #include <linux/pm_runtime.h> #include "coresight-etm-perf.h" @@ -1567,6 +1568,58 @@ void coresight_release_platform_data(struct coresight_device *csdev,coresight_remove_conns_sysfs_group (csdev); } +int coresight_cdev_register (struct coresight_cdev *cdev,const struct file_operations *fops, +const char *name) +{ +struct device *device; +drivers/hwtracing/coresight/coresight-core.c void coresight_release_platform_data(struct coresight_device *csdev, · line 1585
Quoted 10 lines
drivers/hwtracing/coresight/coresight-core.c +10
-0+if (alloc_chrdev_region (&cdev->devno,0 ,1 , name)) { +pr_err ("failed to create the coresight cdev region\n" ); +return -EFAULT ; + } + + cdev->class =class_create (THIS_MODULE , name); +if (IS_ERR (cdev->class)) { +pr_err ("failed to create the coresight class\n" ); + goto coresight_unregister_region; + }From the above a new class is created for every TMC, even if they are all the
same. A better way to do this would be to create a single TMC class with a new cdev for every new TMC.To do this
alloc_chrdev_region()andclass_create()have to be called when the module is added to the system. Have a look atfunnel_init()on how to refactor the TMC core driver with an init function andrpmsg_chrdev_init()for the chrdev region allocation and the class creation.
Quoted 6 lines
From there every time a TMC is probe
cdev_init()andcdev_add()can be called -
look atrpmsg_chrdev_probe()for an example. Instead of using an IDA to pick out a minor number you should be able to usedev_list->nr_idx- 1.Thanks,
Mathieu
Thank you for your suggestion. I will revise it and send another patch
Quoted 168 lines
Quoted 168 lines
drivers/hwtracing/coresight/coresight-core.c +37
-0+ +cdev_init (&cdev->cdev, fops); +if (cdev_add (&cdev->cdev, cdev->devno,1 )) { +pr_err ("failed to add the coresight cdev\n" ); + goto coresight_free_class; + } + + device =device_create (cdev->class,NULL , cdev->devno, + cdev, name); +if (IS_ERR (device)) { +pr_err ("failed to create device for coresight\n" ); + goto coresight_del_cdev; + } + +return 0 ; + +coresight_del_cdev: +cdev_del (&cdev->cdev); +coresight_free_class: +class_destroy (cdev->class); +coresight_unregister_region: +unregister_chrdev_region (cdev->devno,1 ); + +return -EFAULT ; +} +EXPORT_SYMBOL_GPL (coresight_cdev_register); + +int coresight_cdev_unregister (struct coresight_cdev *cdev) +{ +device_destroy (cdev->class, cdev->devno); +cdev_del (&cdev->cdev); +class_destroy (cdev->class); +unregister_chrdev_region (cdev->devno,1 ); +return 0 ; +} +EXPORT_SYMBOL_GPL (coresight_cdev_unregister); +struct coresight_device *coresight_register (struct coresight_desc *desc) {int ret;drivers/hwtracing/coresight/coresight-tmc-core.c +5
-8@@ -147,7 +147,7 @@ static int tmc_open(struct inode *inode, struct file *file) {int ret;struct tmc_drvdata *drvdata =container_of (file->private_data, - struct tmc_drvdata, miscdev); + struct tmc_drvdata, cdev); ret =tmc_read_prepare (drvdata);if (ret)@@ -179,7 +179,7 @@ static ssize_t tmc_read(struct file *file, char __user *data, size_t len,char *bufp;ssize_t actual;struct tmc_drvdata *drvdata =container_of (file->private_data, - struct tmc_drvdata, miscdev); + struct tmc_drvdata, cdev); actual =tmc_get_sysfs_trace (drvdata, *ppos, len, &bufp);if (actual <=0 )return 0 ;@@ -200,7 +200,7 @@ static int tmc_release(struct inode *inode, struct file *file) {int ret;struct tmc_drvdata *drvdata =container_of (file->private_data, - struct tmc_drvdata, miscdev); + struct tmc_drvdata, cdev); ret =tmc_read_unprepare (drvdata);if (ret)@@ -529,10 +529,7 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) goto out; } - drvdata->miscdev.name = desc.name; - drvdata->miscdev.minor =MISC_DYNAMIC_MINOR ; - drvdata->miscdev.fops = &tmc_fops; - ret =misc_register (&drvdata->miscdev); + ret =coresight_cdev_register (&drvdata->cdev, &tmc_fops, desc.name);if (ret)coresight_unregister (drvdata->csdev);else @@ -572,7 +569,7 @@ static void tmc_remove(struct amba_device *adev)* etb fops in this case, device is there until last file * handler to this device is closed. */ -misc_deregister (&drvdata->miscdev); +coresight_cdev_unregister (&drvdata->cdev);coresight_unregister (drvdata->csdev); }drivers/hwtracing/coresight/coresight-tmc.h +2
-2@@ -166,7 +166,7 @@ struct etr_buf {* struct tmc_drvdata - specifics associated to an TMC component * @base: memory mapped base address for this component. * @csdev: component vitals needed by the framework. -* @miscdev: specifics to handle "/dev/xyz.tmc" entry. +* @cdev: specifics to handle "/dev/xyz.tmc" entry. * @spinlock: only one at a time pls. * @pid: Process ID of the process being monitored by the session * that is using this component. @@ -188,7 +188,7 @@ struct etr_buf {struct tmc_drvdata {void __iomem *base;struct coresight_device *csdev; -struct miscdevice miscdev; +struct coresight_cdev cdev;spinlock_t spinlock;pid_t pid;bool reading;include/linux/coresight.h +23
-0@@ -9,6 +9,7 @@#include <linux/device.h> #include <linux/io.h> #include <linux/perf_event.h> +#include <linux/cdev.h> #include <linux/sched.h> /* Peripheral id registers (0xFD0-0xFEC) */ @@ -252,6 +253,12 @@ struct coresight_device {void *active_cscfg_ctxt; }; +struct coresight_cdev { +dev_t devno; +struct class *class; +struct cdev cdev; +}; +/* * coresight_dev_list - Mapping for devices to "name" index for device * names. @@ -506,6 +513,10 @@ void coresight_relaxed_write64(struct coresight_device *csdev, u64 val, u32 offset);void coresight_write64 (struct coresight_device *csdev,u64 val,u32 offset); +int coresight_cdev_register (struct coresight_cdev *cdev,const struct file_operations *fops, +const char *name); + +int coresight_cdev_unregister (struct coresight_cdev *cdev);#else static inline struct coresight_device *coresight_register (struct coresight_desc *desc) {return NULL ; }@@ -581,6 +592,18 @@ static inline void coresight_write64(struct coresight_device *csdev, u64 val, u3 { } +static inline int coresight_cdev_register (struct coresight_cdev *cdev, +const struct file_operations *fops, +const char *name) +{ +return 0 ; +} + +static inline int coresight_cdev_unregister (struct coresight_cdev *cdev) +{ +return 0 ; +} +#endif /* IS_ENABLED(CONFIG_CORESIGHT) */
Quoted 4 lines
Quoted 4 lines
include/linux/coresight.h +0
-0extern int coresight_get_cpu (struct device *dev);Signature · 1 line
2.27.0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel