Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp637889lqp; Fri, 5 Apr 2024 04:47:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXK3YVLY07gJA2qwq5p5b1FeCpzQCgRHVO9gzAjtqzl+4Wn4yQmFCIH76g37Q58uBfDXiDB1eO6T0EW/TporH7GG2eZvmy4PQ2iAy7H9Q== X-Google-Smtp-Source: AGHT+IH9oKmLDsMLYw+0MmMb8FXlRyWTo/vsqLLuqvkopr2MP+x9794VacSck6ahNsH1qHPdY5bX X-Received: by 2002:a05:6a20:3c9e:b0:1a7:23d1:df36 with SMTP id b30-20020a056a203c9e00b001a723d1df36mr1221188pzj.12.1712317658562; Fri, 05 Apr 2024 04:47:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712317658; cv=pass; d=google.com; s=arc-20160816; b=PQGjHPsoM9xA316esdJaFD9k2zEct+M/oPCtXjm4t/jYlofD7hwQfOP7FjQvNw/47B v3xVNXsYKUyAXy4oX3pLnb2dyfMndmPl0p8L/P6vUdc7hdIqz56GLlqJIURJYtJk7cJi cUiNTapzORyAxRxBPIRthqjJL5KoOKogjOMsr9mS5/G+VrI3etHEVNDkQDJjHdCjQsJS ETHdN0HdnsHU/seNhxaIyYJbnYqejQFbzwlpQg2ixLZfB3Mo1oOwpUOErZFeUALb2wuR /SZnwaKLavNEGvqyvVbuXXhyeGmguoYY2rJlzzSzM363rSGAAg2LCtv0e6hCqIjFFzgD lWNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=OHcNBCZnyaiU8rSnCvEaTEJwqqEfQJapCDN0jhOL3as=; fh=lxcLD4MP3gK7uoYpPIXrrd2t5CZolXsWf/qTT29N/k4=; b=MqcD90YEz5E90JMfMjf+SYel1xlwblRW5BLHm56t9gtdwEWxt6LILpOhbdBiXpg/yh psUPISsGZP1E0S/eHpl+FxICPkhHHV9ZD6aubdHrvTuJpN2Mpo5q16jtwXyQVOECLzFK e37kD/Ecq/0bz46GJJG/QdVafvt6EInG0qlCjUsci5JSF826RCKm5mV+/rMqtYl69NlU qALFyooPXSEU0Bjz7tqOK3dP+Zfh9JV02RjFZgWhTfwXVcy59B5uKGVdxN3Toc+ugySI +UdbGSi/sk4FHFgcQ9jcz0edZl2KwhcnF0oHdTdLXnrpo4z5eFhVsXz4i8xtp420ctro usJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=X1r3AAq8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-132922-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132922-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v10-20020a170902f0ca00b001e02dbf555dsi1165948pla.471.2024.04.05.04.47.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 04:47:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132922-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=X1r3AAq8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-132922-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132922-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2CB34284196 for ; Fri, 5 Apr 2024 11:47:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98BE716C6A6; Fri, 5 Apr 2024 11:47:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X1r3AAq8" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C15316CDB7; Fri, 5 Apr 2024 11:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712317652; cv=none; b=kvS399aZb206lunA3AyJ1rufJLClbVpawFYTvazKjTvutxk0peMWANFs4VewWgf2ksSFAPdrXDX8+1jhNwkiiIwhlMSt8hQ4dwTtm/POSteN90COtdSX66s4DXJHicSu9l5TQkTPB9srKQlHqRFPEVDqMJrOATG0sHFF+Nf5j2o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712317652; c=relaxed/simple; bh=DvKJWYggCWh8qsjlglovNAH159U7MAewA0OxcfyHmMk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qSwweWDl+QnmO+ZWZVh4dwxFxQKPxhjzdjHu7h51Surb3kItIdkADJ+aMB06T1waWhJoUCk/KxUYUahF3ojOaB3Qbz+Di6TtZzwDWfbiFiqdh0bJk0XXkI2q3x0s3bYC/5SS2OSOJreyW7A0mTb5k2DT5M8G05Dty2+VGWtD56g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X1r3AAq8; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C19DDC433C7; Fri, 5 Apr 2024 11:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712317652; bh=DvKJWYggCWh8qsjlglovNAH159U7MAewA0OxcfyHmMk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=X1r3AAq8rG6agZ0h394b8G6DI2ZtudUMm5j9cuQBMv2siRMN6hTcARQq5HL4SQRS/ 1oTSxSBlMrI480L+ARtYPRsQ1kXqHkttxYZttBFhJ0XB+Ff+Mjg90yt+8rzZCp6oc5 jOF7KMf9WzDhVmz5TbdiaL4QmZ/V2ja1KgySlkJW39kOkMCtogWGXcxxWJu0E5ZF81 ttnqW1ByP09fTZshu0oiSi7JSig9dPJNOkQ/2QV6wTTIsTcIpZHDc11dIpg9GJacBt OU5PHa1CiI17EpbZFxoLsb4ou0gTiu7OEHhBsw3l+e3j8gS194NUO96i0XyWIPlqer QRDsvljyndIIw== Date: Fri, 5 Apr 2024 17:17:28 +0530 From: Vinod Koul To: Bard Liao Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, pierre-louis.bossart@linux.intel.com, bard.liao@intel.com Subject: Re: [PATCH 7/7] soundwire: bus: add stream refcount Message-ID: References: <20240326090122.1051806-1-yung-chuan.liao@linux.intel.com> <20240326090122.1051806-8-yung-chuan.liao@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240326090122.1051806-8-yung-chuan.liao@linux.intel.com> On 26-03-24, 09:01, Bard Liao wrote: > From: Pierre-Louis Bossart > > The notion of stream is by construction based on a multi-bus > capability, to allow for aggregation of Peripheral devices or > functions located on different segments. We currently count how many > master_rt contexts are used by a stream, but we don't have the dual > refcount of how many streams are allocated on a given bus. This > refcount will be useful to check if BTP/BRA streams can be allocated. > > Note that the stream_refcount is modified in sdw_master_rt_alloc() and > sdw_master_rt_free() which are both called with the bus_lock mutex > held, so there's no need for refcount_ primitives for additional > protection. This lgtm, I would like to see this patch with its user when you allocate BTP/BRA streams > > Signed-off-by: Pierre-Louis Bossart > Reviewed-by: Rander Wang > Signed-off-by: Bard Liao > --- > drivers/soundwire/stream.c | 5 +++++ > include/linux/soundwire/sdw.h | 2 ++ > 2 files changed, 7 insertions(+) > > diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c > index 4e9e7d2a942d..7aa4900dcf31 100644 > --- a/drivers/soundwire/stream.c > +++ b/drivers/soundwire/stream.c > @@ -1181,6 +1181,8 @@ static struct sdw_master_runtime > m_rt->bus = bus; > m_rt->stream = stream; > > + bus->stream_refcount++; > + > return m_rt; > } > > @@ -1217,6 +1219,7 @@ static void sdw_master_rt_free(struct sdw_master_runtime *m_rt, > struct sdw_stream_runtime *stream) > { > struct sdw_slave_runtime *s_rt, *_s_rt; > + struct sdw_bus *bus = m_rt->bus; > > list_for_each_entry_safe(s_rt, _s_rt, &m_rt->slave_rt_list, m_rt_node) { > sdw_slave_port_free(s_rt->slave, stream); > @@ -1226,6 +1229,8 @@ static void sdw_master_rt_free(struct sdw_master_runtime *m_rt, > list_del(&m_rt->stream_node); > list_del(&m_rt->bus_node); > kfree(m_rt); > + > + bus->stream_refcount--; > } > > /** > diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h > index e3a4bccc2a7e..71a7031f7b3a 100644 > --- a/include/linux/soundwire/sdw.h > +++ b/include/linux/soundwire/sdw.h > @@ -902,6 +902,7 @@ struct sdw_master_ops { > * meaningful if multi_link is set. If set to 1, hardware-based > * synchronization will be used even if a stream only uses a single > * SoundWire segment. > + * @stream_refcount: number of streams currently using this bus > */ > struct sdw_bus { > struct device *dev; > @@ -931,6 +932,7 @@ struct sdw_bus { > u32 bank_switch_timeout; > bool multi_link; > int hw_sync_min_links; > + int stream_refcount; > }; > > int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent, > -- > 2.34.1 -- ~Vinod