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=-7.9 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_PATCH,MAILING_LIST_MULTI, MIME_HTML_MOSTLY,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,T_KAM_HTML_FONT_INVALID, USER_AGENT_SANE_1 autolearn=ham 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 A47D5C43603 for ; Thu, 12 Dec 2019 15:07:28 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 723AB2067C for ; Thu, 12 Dec 2019 15:07:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="vTY5CROO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 723AB2067C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=amd-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 226BF6E180; Thu, 12 Dec 2019 15:07:28 +0000 (UTC) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2047.outbound.protection.outlook.com [40.107.92.47]) by gabe.freedesktop.org (Postfix) with ESMTPS id 522C56E180; Thu, 12 Dec 2019 15:07:26 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nxcrA4DPnj3R0raVYvlOxTXTzbm6JwQe9WaPIxjRwAvI5UwqvPDICIRBfGBSWoP+JBrBIIAWgAzofI9SZHokvCEGRd4cQS20/k5O1NAICOzFpIhcFFKbKQR2+Ie/UXzdA9/Efco/lfjhzdylT5EZ7KpyOtWfQwP4ypIYsgBne3RWmSjyK+GgTiICxvB/f44/FCX4+hEM0BKO6HL+XdIl6wAuxvVlo5u5H47KcdycDvwD0oDJgmKqTfv4NAiso6qz+FtidVnKdrXCfynsoo4pQFgGPqhemgl1OpDec1tNzWYJusdHT76nEX70RJbyAxb8k5ZRSxYV7NAHjJG5NSYvBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wmgUjU/xtTcdfONRvEhFvTt1gY744k/RKA+gYEbGUiE=; b=G1Gt9T0p5f7xo0KhRvyVRQMC26nPXUxu7teWPSoko2VbNO7a/ZQM1knFdunP1E8egs5RwgLxQqoBK9g1akhq9KAazdNk2HR7t1kDfJeoGbOTV4FmUu7tCQXxzA+A+PybHgNu6Gnm6qllETQL1mnERjrl49IKGw7e30KO02L1KcLMujSOs0Ml+DCNcPXcFDtahWgd5OMAeUTuiiGi0LO9bSGpZFRwaI+C0HL0LxMIUHhh1solLfa6Z5iYq+My4v/8irZUP17Z4ZFVxXpN8iunlN74ycKFu1k/ibipOa8AZK5B17S80jUUvKO00ujvNQmAQmdk1KNNgzYVtsqCmtbuhA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wmgUjU/xtTcdfONRvEhFvTt1gY744k/RKA+gYEbGUiE=; b=vTY5CROO1qzbr/NfQHy0RtBpjPY4ecpzZy5er/oWjJVwIrc7+5Or9lHu5e+Pi0uQWZ2WYck6DuanQX3y09kNTywc2jnXHRKYSb+/i0tPCwWfcMXxQgmnt+++swsZt7DJdR47EncDQus3qSc7cezZBWqawxCkorn5Juc4Er4q8vM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Andrey.Grodzovsky@amd.com; Received: from MWHPR12MB1453.namprd12.prod.outlook.com (10.172.55.22) by MWHPR12MB1341.namprd12.prod.outlook.com (10.169.205.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2516.17; Thu, 12 Dec 2019 15:07:23 +0000 Received: from MWHPR12MB1453.namprd12.prod.outlook.com ([fe80::514b:dbf8:d19f:a80]) by MWHPR12MB1453.namprd12.prod.outlook.com ([fe80::514b:dbf8:d19f:a80%12]) with mapi id 15.20.2538.016; Thu, 12 Dec 2019 15:07:23 +0000 Subject: Re: [RESEND PATCH 2/5] drm: Add Reusable task barrier. To: "Ma, Le" , "dri-devel@lists.freedesktop.org" , "amd-gfx@lists.freedesktop.org" References: <1576096732-3596-1-git-send-email-andrey.grodzovsky@amd.com> <1576096732-3596-2-git-send-email-andrey.grodzovsky@amd.com> From: Andrey Grodzovsky Message-ID: Date: Thu, 12 Dec 2019 10:07:20 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 In-Reply-To: Content-Language: en-US X-ClientProxiedBy: YTXPR0101CA0058.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00:1::35) To MWHPR12MB1453.namprd12.prod.outlook.com (2603:10b6:301:e::22) MIME-Version: 1.0 X-Originating-IP: [2607:fea8:3edf:e127:3a1e:65e:fc37:38e9] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7da40e1d-46d1-4e9f-0872-08d77f14fdc3 X-MS-TrafficTypeDiagnostic: MWHPR12MB1341:|MWHPR12MB1341: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-Forefront-PRVS: 0249EFCB0B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(39830400003)(346002)(376002)(396003)(366004)(199004)(189003)(13464003)(53546011)(52116002)(6506007)(186003)(36756003)(6512007)(2616005)(450100002)(54906003)(4326008)(508600001)(110136005)(31686004)(33964004)(31696002)(2906002)(8936002)(66556008)(81166006)(86362001)(66946007)(5660300002)(8676002)(6486002)(66476007)(81156014)(30864003); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1341; H:MWHPR12MB1453.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1X0KCUvCGCChqTBsFTQTL8bPKSM73K0/fdWQve9eblobFpwCrSsp2aIHiQBsy2lPMwmJc+Fo4CBDbD2SLDvSTlBHGSfFQvCHXccrKm8LoZYFHDX88vnjcbVhdl+QmZ0MWRAfUhBuh1kgTz+nleFFGABHF9lbek+UM64t0TgNEjBMR3UwAgm5xsG+4xbBy7G3rgNDBiXmEtyjB2M1DcoVDRVsgENio+mVuIF8HCEvyrwlnfcAnsJ4NXAQOsQCBsD58r7kBJda1yKLXXb5yDY3lD9TK834lZZK1ZvbJjHLGs19L2cQiivSykpH4qPX1RA0X4B5oOvX6LGKkGjujW/HA+J8ayzE1Ou2Ewk3eHZMkPiNJxViCbQFKnUunl/iY65VRMDxM/l9QM2jL3NqQTSdQwoX4LLKmywgr3t9oBTnbXWhMIF/bLEGeKFcp2YAHmzBS1Mv2qqXvEjNtKFE6zD51WGP6EuxB9cXpt+ZIA5uymYraqHIAU+R1gBPDJPyVn5H X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7da40e1d-46d1-4e9f-0872-08d77f14fdc3 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2019 15:07:23.3073 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: momw83947izgZxccbG0kFzoMdY7Lgwir4rHnRq7Nn3azIrgaf92MYB4UndQ6F8pwAL5dhBK5Z0epcunZH/5Ufw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1341 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Deucher, Alexander" , "Quan, Evan" , "Zhang, Hawking" Content-Type: multipart/mixed; boundary="===============1483991083==" Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" --===============1483991083== Content-Type: multipart/alternative; boundary="------------9884471CDF8D2917872047BE" Content-Language: en-US --------------9884471CDF8D2917872047BE Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 12/11/19 11:04 PM, Ma, Le wrote: > > [AMD Official Use Only - Internal Distribution Only] > > -----Original Message----- > From: Andrey Grodzovsky > Sent: Thursday, December 12, 2019 4:39 AM > To: dri-devel@lists.freedesktop.org; amd-gfx@lists.freedesktop.org > Cc: Deucher, Alexander ; Ma, Le > ; Zhang, Hawking ; Quan, Evan > ; Grodzovsky, Andrey > Subject: [RESEND PATCH 2/5] drm: Add Reusable task barrier. > > It is used to synchronize N threads at a rendevouz point before > execution of critical code that has to be started by all the threads > at approximatly the same time. > > Signed-off-by: Andrey Grodzovsky > > > --- > > include/drm/task_barrier.h | 106 > +++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 106 insertions(+) > > create mode 100644 include/drm/task_barrier.h > > diff --git a/include/drm/task_barrier.h b/include/drm/task_barrier.h > new file mode 100644 index 0000000..81fb0f7 > > --- /dev/null > > +++ b/include/drm/task_barrier.h > > @@ -0,0 +1,106 @@ > > +/* > > + * Copyright 2019 Advanced Micro Devices, Inc. > > + * > > + * Permission is hereby granted, free of charge, to any person > > +obtaining a > > + * copy of this software and associated documentation files (the > > +"Software"), > > + * to deal in the Software without restriction, including without > > +limitation > > + * the rights to use, copy, modify, merge, publish, distribute, > > +sublicense, > > + * and/or sell copies of the Software, and to permit persons to whom > > +the > > + * Software is furnished to do so, subject to the following conditions: > > + * > > + * The above copyright notice and this permission notice shall be > > +included in > > + * all copies or substantial portions of the Software. > > + * > > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, > > +EXPRESS OR > > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF > > +MERCHANTABILITY, > > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT > > +SHALL > > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, > > +DAMAGES OR > > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR > > +OTHERWISE, > > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE > > +OR > > + * OTHER DEALINGS IN THE SOFTWARE. > > + * > > + */ > > +#include > > +#include > > + > > +/* > > + * Reusable 2 PHASE task barrier (randevouz point) implementation for > N tasks. > > + * Based on the Little book of sempahores - > > +https://greenteapress.com/wp/semaphores/ > > + */ > > + > > + > > + > > +#ifndef DRM_TASK_BARRIER_H_ > > +#define DRM_TASK_BARRIER_H_ > > + > > [Le]: It might be better to prefix “drm_” to the functions and > structure below, even this header file name. > I am not sure about this - see the example of spsc_queue we added for GPU scheduler use. I just followed it as an example of where to place the structure. There is nothing DRM specific about spsc_queue or task_barrier, they are generic constructs that we place in DRM subsystem for common use. > +/* > > + * Represents an instance of a task barrier. > > + */ > > +struct task_barrier { > > +          unsigned int n; > > [Le]: We can define it as signed type here for more common use. > This is a counter of number of tasks/threads to synchronize in the barrier it cannot go bellow 0 Andrey > +          atomic_t count; > > +          struct semaphore enter_turnstile; > > +          struct semaphore exit_turnstile; > > +}; > > + > > +static inline void task_barrier_signal_turnstile(struct semaphore > *turnstile, > > + unsigned int n) > > +{ > > +          int i; > > + > > +          for (i = 0 ; i < n; i++) > > +                      up(turnstile); > > +} > > + > > +static inline void task_barrier_init(struct task_barrier *tb) { > > +          tb->n = 0; > > +          atomic_set(&tb->count, 0); > > + sema_init(&tb->enter_turnstile, 0); > > + sema_init(&tb->exit_turnstile, 0); > > +} > > + > > +static inline void task_barrier_add_task(struct task_barrier *tb) { > > +          tb->n++; > > +} > > + > > +static inline void task_barrier_rem_task(struct task_barrier *tb) { > > +          tb->n--; > > +} > > + > > +/* > > + * Lines up all the threads BEFORE the critical point. > > + * > > + * When all thread passed this code the entry barrier is back to > locked state. > > + */ > > +static inline void task_barrier_enter(struct task_barrier *tb) { > > +          if (atomic_inc_return(&tb->count) == tb->n) > > + task_barrier_signal_turnstile(&tb->enter_turnstile, tb->n); > > + > > + down(&tb->enter_turnstile); > > +} > > + > > +/* > > + * Lines up all the threads AFTER the critical point. > > + * > > + * This function is used to avoid any one thread running ahead of the > > +reset if > > [Le]: No need to mention “reset” here. > > With the above addressed, Acked-by: Le Ma Le.Ma@amd.com > > > Regards, > > Ma Le > > + * the barrier is used in a loop (repeatedly) . > > + */ > > +static inline void task_barrier_exit(struct task_barrier *tb) { > > +          if (atomic_dec_return(&tb->count) == 0) > > + task_barrier_signal_turnstile(&tb->exit_turnstile, tb->n); > > + > > + down(&tb->exit_turnstile); > > +} > > + > > +static inline void task_barrier_full(struct task_barrier *tb) { > > +          task_barrier_enter(tb); > > +          task_barrier_exit(tb); > > +} > > + > > +#endif > > -- > > 2.7.4 > --------------9884471CDF8D2917872047BE Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit


On 12/11/19 11:04 PM, Ma, Le wrote:

[AMD Official Use Only - Internal Distribution Only]

 

 

 

-----Original Message-----
From: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Sent: Thursday, December 12, 2019 4:39 AM
To: dri-devel@lists.freedesktop.org; amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Ma, Le <Le.Ma@amd.com>; Zhang, Hawking <Hawking.Zhang@amd.com>; Quan, Evan <Evan.Quan@amd.com>; Grodzovsky, Andrey <Andrey.Grodzovsky@amd.com>
Subject: [RESEND PATCH 2/5] drm: Add Reusable task barrier.

 

It is used to synchronize N threads at a rendevouz point before execution of critical code that has to be started by all the threads at approximatly the same time.

 

Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>

---

include/drm/task_barrier.h | 106 +++++++++++++++++++++++++++++++++++++++++++++

1 file changed, 106 insertions(+)

create mode 100644 include/drm/task_barrier.h

 

diff --git a/include/drm/task_barrier.h b/include/drm/task_barrier.h new file mode 100644 index 0000000..81fb0f7

--- /dev/null

+++ b/include/drm/task_barrier.h

@@ -0,0 +1,106 @@

+/*

+ * Copyright 2019 Advanced Micro Devices, Inc.

+ *

+ * Permission is hereby granted, free of charge, to any person

+obtaining a

+ * copy of this software and associated documentation files (the

+"Software"),

+ * to deal in the Software without restriction, including without

+limitation

+ * the rights to use, copy, modify, merge, publish, distribute,

+sublicense,

+ * and/or sell copies of the Software, and to permit persons to whom

+the

+ * Software is furnished to do so, subject to the following conditions:

+ *

+ * The above copyright notice and this permission notice shall be

+included in

+ * all copies or substantial portions of the Software.

+ *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,

+EXPRESS OR

+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

+MERCHANTABILITY,

+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

+SHALL

+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,

+DAMAGES OR

+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

+OTHERWISE,

+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

+OR

+ * OTHER DEALINGS IN THE SOFTWARE.

+ *

+ */

+#include <linux/semaphore.h>

+#include <linux/atomic.h>

+

+/*

+ * Reusable 2 PHASE task barrier (randevouz point) implementation for N tasks.

+ * Based on the Little book of sempahores -

+https://greenteapress.com/wp/semaphores/

+ */

+

+

+

+#ifndef DRM_TASK_BARRIER_H_

+#define DRM_TASK_BARRIER_H_

+

 

[Le]: It might be better to prefix “drm_” to the functions and structure below, even this header file name.


I am not sure about this - see the example of spsc_queue we added for GPU scheduler use. I just followed it as an example of where to place the structure. There is nothing DRM specific about  spsc_queue or task_barrier, they are generic constructs that we place in DRM subsystem for common use.


 

+/*

+ * Represents an instance of a task barrier.

+ */

+struct task_barrier {

+          unsigned int n;

[Le]: We can define it as signed type here for more common use.


This is a counter of number of tasks/threads to synchronize in the barrier it cannot go bellow 0

Andrey


+          atomic_t count;

+          struct semaphore enter_turnstile;

+          struct semaphore exit_turnstile;

+};

+

+static inline void task_barrier_signal_turnstile(struct semaphore *turnstile,

+                                                                      unsigned int n)

+{

+          int i;

+

+          for (i = 0 ; i < n; i++)

+                      up(turnstile);

+}

+

+static inline void task_barrier_init(struct task_barrier *tb) {

+          tb->n = 0;

+          atomic_set(&tb->count, 0);

+          sema_init(&tb->enter_turnstile, 0);

+          sema_init(&tb->exit_turnstile, 0);

+}

+

+static inline void task_barrier_add_task(struct task_barrier *tb) {

+          tb->n++;

+}

+

+static inline void task_barrier_rem_task(struct task_barrier *tb) {

+          tb->n--;

+}

+

+/*

+ * Lines up all the threads BEFORE the critical point.

+ *

+ * When all thread passed this code the entry barrier is back to locked state.

+ */

+static inline void task_barrier_enter(struct task_barrier *tb) {

+          if (atomic_inc_return(&tb->count) == tb->n)

+                      task_barrier_signal_turnstile(&tb->enter_turnstile, tb->n);

+

+          down(&tb->enter_turnstile);

+}

+

+/*

+ * Lines up all the threads AFTER the critical point.

+ *

+ * This function is used to avoid any one thread running ahead of the

+reset if

[Le]: No need to mention “reset” here.

 

With the above addressed, Acked-by: Le Ma Le.Ma@amd.com

 

Regards,

Ma Le

+ * the barrier is used in a loop (repeatedly) .

+ */

+static inline void task_barrier_exit(struct task_barrier *tb) {

+          if (atomic_dec_return(&tb->count) == 0)

+                      task_barrier_signal_turnstile(&tb->exit_turnstile, tb->n);

+

+          down(&tb->exit_turnstile);

+}

+

+static inline void task_barrier_full(struct task_barrier *tb) {

+          task_barrier_enter(tb);

+          task_barrier_exit(tb);

+}

+

+#endif

--

2.7.4

 

--------------9884471CDF8D2917872047BE-- --===============1483991083== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx --===============1483991083==--