From patchwork Fri Feb 12 12:13:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 12085195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CF2CC433E0 for ; Fri, 12 Feb 2021 12:20:40 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0CE8764E36 for ; Fri, 12 Feb 2021 12:20:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0CE8764E36 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=uJ0JAxIYBITj9DURH1iA6WibRXIq+kRUWeqf++vWQZw=; b=mPazGMVJGDsybdGHC+ssQDyK2 sqE6eDTpExYN4xTfVrITpJORWd4SnKlBnm17+S83eOHlmjYxFpeQ1JOF8xMi38jjsdqWc4f7XC7c1 IBAPLGEuQPE4e2jIrkjmS9/dCTepG32QN5GspHl9KKLPYdiSTCW85CcWt5fUZ6VTy0/9RnaStFa9Z JAm5Cgr6PszUoATkBC/A91lfHrSWLrOXfoPTFlDW0Kn9ux4YhXJGPNJWmcuq1vXVgFpkltvHcr2QU U4nI3XdfpMVSfn1tIHBgZz03ch7Fk+CKDVP8dTpZIKfMflVnmBGXHD1xLVfDD/nVxMjU9OPdDUxxM pJ3C+Ibzw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAXOv-00089j-Lz; Fri, 12 Feb 2021 12:18:23 +0000 Received: from mail-qk1-x734.google.com ([2607:f8b0:4864:20::734]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAXMf-0006y2-C9 for linux-arm-kernel@lists.infradead.org; Fri, 12 Feb 2021 12:16:03 +0000 Received: by mail-qk1-x734.google.com with SMTP id v206so8427542qkb.3 for ; Fri, 12 Feb 2021 04:16:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/dq5yGecHRhOL4H/a5G1r5U6YeS+IFkmZnnpivpRxz0=; b=tXuGmxOXZjyIYnc4JHpPzHer/gQ/umhTIRqUuJ8cQa50uqekdJsbA3h4EjtioeGFxf JzwqtuRbhjg93Xn6RmJKEsnyxlyrkHHxrrQ3KqFTY/T2O2DY8j5ewbwqeCk+s+3zpwxH xNxCx1U3I/x3naLWre8EkQ/OBUhzEvBxw+H6FBh1qkwk1EVwxgBHk7FKb/YNSitaE6Ej 3m0tTTFo1DhblZnvyD1mCLom3p4J8e+rikkdVJEGIYeT1vrZVN5WaerN6EK41zEHUOOd 2ExeSBjDylw5hwCmMp/7gg0C37QwFBoEUp2jbcN/jBB2T1r1cKcP3CNwX4My6Qu3Vk3t 4fLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/dq5yGecHRhOL4H/a5G1r5U6YeS+IFkmZnnpivpRxz0=; b=WTo73BoXBk3g0vCEskHejKhLEbQb2y56U7xqI5poaXDkMVcT6dl8RiHnvqYrEPst4F 2+tMMHH/ZHzpLl7/U+2TKpR5po2YpuN1rSP82xbEeNWpw52JmdBY5MxmMfEntganYJWe QQMWtj3u126KKJae1mnhm/FGopl6yqmwTAT1FiUixbXeZKajt7YkS37f+GHkKro6XdqI A5WVDUKvmeQMaIC6iG2VjfG0e0ifjmm3vS3WmWms1RBWPtUOqi85tRojeofdivEKIjq7 4EZi7S5gtuG5zotGwjHIzhqmvd7pBre+JW3rbaf+xRq4TJsRITKFbA24m+HY5q//68tU B8vA== X-Gm-Message-State: AOAM533UB5PEgGbXhjLLq/l1benSLtBqEcQPsa1Rxaumew+va8/NgiTi CUMUNbosLnJi0YdL1NywZGI= X-Google-Smtp-Source: ABdhPJx+MOrmlkkISgi4I5vYgi3Ar2qnU+GE7hatn2Dxgegz33X0EKpQOMpBeF7PGWv4qKwzr0vY+Q== X-Received: by 2002:a05:620a:b13:: with SMTP id t19mr2354370qkg.300.1613132159258; Fri, 12 Feb 2021 04:15:59 -0800 (PST) Received: from localhost.localdomain ([193.27.12.132]) by smtp.gmail.com with ESMTPSA id y135sm6278534qkb.14.2021.02.12.04.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Feb 2021 04:15:58 -0800 (PST) From: William Breathitt Gray To: jic23@kernel.org Subject: [PATCH v8 20/22] counter: Implement events_queue_size sysfs attribute Date: Fri, 12 Feb 2021 21:13:44 +0900 Message-Id: <013b2b8682ddc3c85038083e6d5567696b6254b3.1613131238.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210212_071601_964643_5B478ED5 X-CRM114-Status: GOOD ( 20.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org, a.fatoum@pengutronix.de, david@lechnology.com, linux-iio@vger.kernel.org, patrick.havelange@essensium.com, alexandre.belloni@bootlin.com, mcoquelin.stm32@gmail.com, linux-kernel@vger.kernel.org, o.rempel@pengutronix.de, kernel@pengutronix.de, William Breathitt Gray , fabrice.gasnier@st.com, syednwaris@gmail.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, alexandre.torgue@st.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The events_queue_size sysfs attribute provides a way for users to dynamically configure the Counter events queue size for the Counter character device interface. The size is in number of struct counter_event data structures. The number of elements will be rounded-up to a power of 2 due to a requirement of the kfifo_alloc function called during reallocation of the queue. Cc: Oleksij Rempel Signed-off-by: William Breathitt Gray --- Documentation/ABI/testing/sysfs-bus-counter | 8 +++++++ drivers/counter/counter-chrdev.c | 23 +++++++++++++++++++ drivers/counter/counter-chrdev.h | 2 ++ drivers/counter/counter-sysfs.c | 25 +++++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-counter b/Documentation/ABI/testing/sysfs-bus-counter index 847e96f19d19..f6cb2a8b08a7 100644 --- a/Documentation/ABI/testing/sysfs-bus-counter +++ b/Documentation/ABI/testing/sysfs-bus-counter @@ -212,6 +212,14 @@ Description: both edges: Any state transition. +What: /sys/bus/counter/devices/counterX/events_queue_size +KernelVersion: 5.13 +Contact: linux-iio@vger.kernel.org +Description: + Size of the Counter events queue in number of struct + counter_event data structures. The number of elements will be + rounded-up to a power of 2. + What: /sys/bus/counter/devices/counterX/name KernelVersion: 5.2 Contact: linux-iio@vger.kernel.org diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c index 16f02df7f73d..53eea894e13f 100644 --- a/drivers/counter/counter-chrdev.c +++ b/drivers/counter/counter-chrdev.c @@ -375,6 +375,29 @@ void counter_chrdev_remove(struct counter_device *const counter) cdev_del(&counter->chrdev); } +int counter_chrdev_realloc_queue(struct counter_device *const counter, + size_t queue_size) +{ + int err; + DECLARE_KFIFO_PTR(events, struct counter_event); + unsigned long flags; + + /* Allocate new events queue */ + err = kfifo_alloc(&events, queue_size, GFP_ATOMIC); + if (err) + return err; + + raw_spin_lock_irqsave(&counter->events_list_lock, flags); + + /* Swap in new events queue */ + kfifo_free(&counter->events); + counter->events.kfifo = events.kfifo; + + raw_spin_unlock_irqrestore(&counter->events_list_lock, flags); + + return 0; +} + static int counter_get_data(struct counter_device *const counter, const struct counter_comp_node *const comp_node, u64 *const value) diff --git a/drivers/counter/counter-chrdev.h b/drivers/counter/counter-chrdev.h index cf5a318fe540..ff7fb0191852 100644 --- a/drivers/counter/counter-chrdev.h +++ b/drivers/counter/counter-chrdev.h @@ -12,5 +12,7 @@ int counter_chrdev_add(struct counter_device *const counter, const dev_t counter_devt); void counter_chrdev_remove(struct counter_device *const counter); +int counter_chrdev_realloc_queue(struct counter_device *const counter, + size_t queue_size); #endif /* _COUNTER_CHRDEV_H_ */ diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c index 0cb3dba950bc..9abc821a3871 100644 --- a/drivers/counter/counter-sysfs.c +++ b/drivers/counter/counter-sysfs.c @@ -13,6 +13,7 @@ #include #include +#include "counter-chrdev.h" #include "counter-sysfs.h" /** @@ -737,12 +738,30 @@ static int counter_num_counts_read(struct counter_device *counter, u8 *val) return 0; } +static int counter_events_queue_size_read(struct counter_device *counter, + u64 *val) +{ + *val = counter->events.kfifo.mask + 1; + return 0; +} + +static int counter_events_queue_size_write(struct counter_device *counter, + u64 val) +{ + return counter_chrdev_realloc_queue(counter, val); +} + static struct counter_comp counter_num_signals_comp = COUNTER_COMP_DEVICE_U8("num_signals", counter_num_signals_read, NULL); static struct counter_comp counter_num_counts_comp = COUNTER_COMP_DEVICE_U8("num_counts", counter_num_counts_read, NULL); +static struct counter_comp counter_events_queue_size_comp = + COUNTER_COMP_DEVICE_U64("events_queue_size", + counter_events_queue_size_read, + counter_events_queue_size_write); + static int counter_sysfs_attr_add(struct counter_device *const counter, struct counter_attribute_group *group) { @@ -781,6 +800,12 @@ static int counter_sysfs_attr_add(struct counter_device *const counter, if (err < 0) return err; + /* Create num_counts attribute */ + err = counter_attr_create(dev, group, &counter_events_queue_size_comp, + scope, NULL); + if (err < 0) + return err; + /* Create an attribute for each extension */ for (i = 0; i < counter->num_ext; i++) { ext = counter->ext + i;