From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4BC9AC433EF for ; Thu, 9 Dec 2021 18:08:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uL7zFJXHPeYVo5+SLiAmBB5YCft/n0zPracspW65Bvs=; b=O8r8aHF0dXGFmu 4q6636u5J5wgzp4m4ZmKdSaI57vIqJW/C5FRjqkQoq9vpPdCm9xD/5uRn3JSvCVG2p60x6YiN16BJ awiBWUgkh5gxxVBacLjUhGfF9ciX5ZUYCq/+NEcApkGbWw2W2jIOZ+W90j7HbYJEJhnk3i4O2ZkZq 1x4upJ9aV224sh+jFjtRJoWNNmM13B0iI+AbNjqtWQEep7/xc9xeO+NflF7XERvKIB+J3+Iv4Zlkf sJ+IbphGVBeZX1GbrbcqP84/XYrVVnuUhbtdPLin6xJHowXUlCi4Q/1W6tZKQI7M/B2UyXEcm3KbX B45Xg0VRK33VIZStSN+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvNoC-00H8Dw-PA; Thu, 09 Dec 2021 18:06:22 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvNlX-00H7Zg-2U for linux-arm-kernel@lists.infradead.org; Thu, 09 Dec 2021 18:03:37 +0000 Received: by mail-pg1-x529.google.com with SMTP id l18so1063843pgj.9 for ; Thu, 09 Dec 2021 10:03:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=CJrNGoIHBc1awK0iGbKzDIyBkYvhG5rV+46cMHZVe+o=; b=WI3/IWXrpWmneAKU8eeAzgQmxoTrKnJvwP2el5cV7373k8ujCogQIITgp+Vm88ZRgV 3C4FAABZFdajWjyA01hHa+o+z2I0JxsjCK+EpiewH5RIl4gu3nHoNnA3dbKo0upLsRYN ie/3EC085TTlJEd7w+PL3SViTaJzT4K+rZj4MFdECHtyaJxhk6pLyBz2UHFMe4Y7gOh2 o3DfJlXzkEb8nuzfnnu5x0N8nvu/LaWQl8a2YjK8t97S2J+MT3WegdS4dPV/VHO/Oz7f f0u4ZUiRVtXKM5QtBbcBuC8/alJRR8L8q9hN4KH0yqo5v0PtdEMEjuHcPV6kqJCMdSIc /Y4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=CJrNGoIHBc1awK0iGbKzDIyBkYvhG5rV+46cMHZVe+o=; b=JmIO12qAnw3MmAHbBftW1gAzLNBtQ0ClE01oAxapR4nLlPoaS+I8/6nSSPqni0nNr+ CzBzwiln1gveJuJL4xCg66jzLLCkRL55b0wPGYt8qXW3Rrd/K0OGLENoUhM6mmdZBid+ Pvb5TmbFIucjKBPP6KLLwTbYaoLLy5a9nLieyAZENe7d0cRO/6L/nmD7RSNBo+1YnFe4 8M6QAZy1uL4nzuBIJByB4Q7mGSYncDpXo2tpSYXcOxLUDxLbGUhPyNmp31gS6Y8rOLYy vVOm2id6n4cYop4MX979Mo4l35PR0IcpJGBEw4DEv5wWo0RNBrF0a2ASeE3x5+EgB6Zh PKXw== X-Gm-Message-State: AOAM532gE+1WbTSbCjFq6zeE30aSw8imVG1FvPQbVdYAJugBU7KWD5ma HulLGKNQ1AWERrbmMImheCsSrA== X-Google-Smtp-Source: ABdhPJydw6L4P8z+4umpn8gGhO2Svi7dCRHq0UXGcVxsxJ9KVSQ3u2llkLmqYhXNptrFrz9z1Cbo6A== X-Received: by 2002:a63:e04f:: with SMTP id n15mr35138226pgj.31.1639073012495; Thu, 09 Dec 2021 10:03:32 -0800 (PST) Received: from p14s (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id h6sm342847pfh.82.2021.12.09.10.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Dec 2021 10:03:31 -0800 (PST) Date: Thu, 9 Dec 2021 11:03:29 -0700 From: Mathieu Poirier To: Jay Chen Cc: suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, mike.leach@linaro.org, leo.yan@linaro.org, zhangliguang@linux.alibaba.com Subject: Re: [RFC PATCH] Change coresight tmc from misc device to cdev device Message-ID: <20211209180329.GA1198739@p14s> References: <20211201070942.24947-1-jkchen@linux.alibaba.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211201070942.24947-1-jkchen@linux.alibaba.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211209_100335_219748_3B7EDB94 X-CRM114-Status: GOOD ( 37.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Jay, On Wed, Dec 01, 2021 at 03:09:42PM +0800, Jay Chen wrote: > 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? > Signed-off-by: Jay Chen > --- > 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(-) > > diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c > index 8a18c71df37a..b0cca3060f4e 100644 > --- a/drivers/hwtracing/coresight/coresight-core.c > +++ b/drivers/hwtracing/coresight/coresight-core.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include > > #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; > + } >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 > + > + 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; > diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c > index 74c6323d4d6a..c4aae8ff65eb 100644 > --- a/drivers/hwtracing/coresight/coresight-tmc-core.c > +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c > @@ -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); > } > > diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h > index b91ec7dde7bc..c37e2ed1cb9d 100644 > --- a/drivers/hwtracing/coresight/coresight-tmc.h > +++ b/drivers/hwtracing/coresight/coresight-tmc.h > @@ -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; > diff --git a/include/linux/coresight.h b/include/linux/coresight.h > index 93a2922b7653..aebe8b8327ad 100644 > --- a/include/linux/coresight.h > +++ b/include/linux/coresight.h > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > #include > > /* 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); > -- > 2.27.0 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel