Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp676462pxu; Wed, 14 Oct 2020 10:46:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkcH622eOM6qJ0V91Tt1LADeAlc24TOQ1B4axC1B1s9HB4pi38fEgnIDW2gjx8W8ZGQVmw X-Received: by 2002:a05:6402:128c:: with SMTP id w12mr50494edv.242.1602697578875; Wed, 14 Oct 2020 10:46:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602697578; cv=none; d=google.com; s=arc-20160816; b=YfZcJyL2Tt4LUu0cVz0l72JfQiwDNjKerpoUtZSAuo+zKExJqIizbWaw3P5Pw1KR8a MWrUItrqlmqeZByvqHvIxMB07wuQASjoHDld722iNY2JmmEcGwc4BPZ4kR/lcCwpe5Ri oHWZK5OHrKPPH/31ZMdwv1ecvUaCvvfrJm3ViRQR2r9dagvoP+VMTIpiKdGRj+Utyje8 kHA951o+ELp4sCngOKSrlCG07EtnRo79SGc7FDBAY0exDpxfBdar99FvQDemqbhEfFSj /u2GUaGXprChmeiWfL8oYdubjJU0iSS6zeVYs7+HquNl50zzB/tCBsGJL/geklzJUoM2 mUrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=UycfqN5oK6kufoVgux//wk8MuMMBk9zPUgTss3ONB0c=; b=vHUkopMU+/tg2oo9tH1q+Bcj0g68y7LQmz9O7tTllQgU3yZ1LKBr3300kXBu8b+lcD zZRCfixSwtyYzmTlgn74XDsrsVdWrFi5jThmMROz+9wowPgMOXNHdROqCb9wT9tvSWib Ytah6iL47Rrzf2AeLka9lbxHKETRNxU9jZ8m3zQZghR0FrVvcYSq03oGwUvWhDmN2WfH OTcO+kZFuQ96b+ecUVYbHPL1+GzRqfbLvzCgfGpcxW9ogEqt+uwIvj5WdGdz9GlUuXRt lmw26S7T/fTyR1h/Wj4nZRKhtc0atmdDaMpBcpY8zFK3iKFyYFdx9rqrfs65mnEcwQ6F YoLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=wHq2o4Ke; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ci22si247375ejc.413.2020.10.14.10.45.56; Wed, 14 Oct 2020 10:46:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=wHq2o4Ke; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727705AbgJNRnP (ORCPT + 99 others); Wed, 14 Oct 2020 13:43:15 -0400 Received: from vern.gendns.com ([98.142.107.122]:50470 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727439AbgJNRnO (ORCPT ); Wed, 14 Oct 2020 13:43:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=UycfqN5oK6kufoVgux//wk8MuMMBk9zPUgTss3ONB0c=; b=wHq2o4Kee8YPcgtZ/kUgnDLx3p aHtlbSGD1QGaWT/zBEPJSlYMfi46Tto3eW5lirxgHEy8pVM0CvxgtpQl2UjWWj7Ocf9Az6CJe5Ow+ p0xxFVRoOn8cRpI2oSPZt2Ly9dZibh675vBIVTJVVOYSYlDq147t/RHZxdvdoQBu3m1dvFB22wVXp GGlMTLVv4cL/lVR+tBOCoTaUsYXoimOmfzvafZ4Gnq8rwSgPk9yHKmqYasKFIEoz34aOtsDH5qqSq YAKdBk0/9sbotjTEoSCGUy10jdEKqmHEOlRiyo2sOGWBNKCdVO+lKC8A8huAFHpCXbCkn45oNXU+M klArMLeQ==; Received: from [2600:1700:4830:165f::19e] (port=44064) by vern.gendns.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1kSknu-000749-Fy; Wed, 14 Oct 2020 13:43:10 -0400 Subject: Re: [PATCH v5 3/5] counter: Add character device interface To: William Breathitt Gray , jic23@kernel.org Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.belloni@bootlin.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com, patrick.havelange@essensium.com, fabrice.gasnier@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com References: <00be1fccc672c5207f3b04fe4cc09c29e22641f4.1601170670.git.vilhelm.gray@gmail.com> From: David Lechner Message-ID: <67a0290e-731b-822a-5113-30b56bde6c88@lechnology.com> Date: Wed, 14 Oct 2020 12:43:08 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <00be1fccc672c5207f3b04fe4cc09c29e22641f4.1601170670.git.vilhelm.gray@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/26/20 9:18 PM, William Breathitt Gray wrote: > diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c > new file mode 100644 > index 000000000000..2be3846e4105 > --- /dev/null > +++ b/drivers/counter/counter-chrdev.c > +/** > + * counter_push_event - queue event for userspace reading > + * @counter: pointer to Counter structure > + * @event: triggered event > + * @channel: event channel > + * > + * Note: If no one is watching for the respective event, it is silently > + * discarded. > + * > + * RETURNS: > + * 0 on success, negative error number on failure. > + */ > +int counter_push_event(struct counter_device *const counter, const u8 event, > + const u8 channel) > +{ > + struct counter_event ev = {0}; > + unsigned int copied = 0; > + unsigned long flags; > + struct counter_event_node *event_node; > + struct counter_comp_node *comp_node; > + int err; > + > + ev.timestamp = ktime_get_ns(); > + ev.watch.event = event; > + ev.watch.channel = channel; > + > + raw_spin_lock_irqsave(&counter->events_lock, flags); > + > + /* Search for event in the list */ > + list_for_each_entry(event_node, &counter->events_list, l) > + if (event_node->event == event && > + event_node->channel == channel) > + break; > + > + /* If event is not in the list */ > + if (&event_node->l == &counter->events_list) > + goto exit_early; > + > + /* Read and queue relevant comp for userspace */ > + list_for_each_entry(comp_node, &event_node->comp_list, l) { > + err = counter_get_data(counter, comp_node, &ev.value_u8); Currently all counter devices are memory mapped devices so calling counter_get_data() here with interrupts disabled is probably OK, but if any counter drivers are added that use I2C/SPI/etc. that will take a long time to read, it would cause problems leaving interrupts disabled here. Brainstorming: Would it make sense to separate the event from the component value being read? As I mentioned in one of my previous reviews, I think there are some cases where we would just want to know when an event happened and not read any additional data anyway. In the case of a slow communication bus, this would also let us queue the event in the kfifo and notify poll right away and then defer the reads in a workqueue for later. > + if (err) > + goto err_counter_get_data; > + > + ev.watch.component = comp_node->component; > + > + copied += kfifo_put(&counter->events, ev); > + } > + > + if (copied) > + wake_up_poll(&counter->events_wait, EPOLLIN); > + > +exit_early: > + raw_spin_unlock_irqrestore(&counter->events_lock, flags); > + > + return 0; > + > +err_counter_get_data: > + raw_spin_unlock_irqrestore(&counter->events_lock, flags); > + return err; > +}