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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 43407C4167D for ; Mon, 13 Nov 2023 15:31:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C420C10E3A7; Mon, 13 Nov 2023 15:31:01 +0000 (UTC) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2072.outbound.protection.outlook.com [40.107.243.72]) by gabe.freedesktop.org (Postfix) with ESMTPS id 70C4C10E3A7 for ; Mon, 13 Nov 2023 15:31:00 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PzcwWBu65Ej8Ff3nVwMqFmHJvyinGtru0yiCZdhJ402LMCRwSAb7o42MVDn/khSneDwUDYd2DfI/ufOiayDDdPnQ8iMOe9l1Wx8Al9E29WA2Nuv8dBCzec3hC6IXJO8F7flun3oeX/aP/xFY1jm0N+wgUrjyKy8ecIwDv2xudE5B3hBFti0IoCV7B1VAH8YclddkG1AVT55R4v0cI5Y5vMPaseMkbZ+/gALuZJf+Ky6g/PtrGNLEv/ZwDgINVzhJC2fE5Kdl22rOttyejdGhU3TXWrtnozbXtQUdqON6NU/6hr6VxuCb4VSHn3P/a+XfYW9l1E3E4k/ngMbvIhzUBA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UNxvjwdXjTJcHYFreJM0nbv+SRwO6xEr6/vyMOPDePw=; b=GBP+IBsgRXvYh8YcLL/J9IwEghxFutplIpAPMRs5ZAoKbU4GtNbMY2WlzczJT+mk8l/HDLsIryHGbd5hXFd1e7xsL7du5BV5OgrsP940qDSkMhULu6sroersovt5lrrwJM4UqVFMyQdD9sJT8ZlU/LS1XUGlCVworqJStXdE/ndlha4arEkRO5xuZYgGSNjomedwNiM89A112eLTrSd51MfJ5wpdNTntGsTXGVo8gxPyt8NVAWfvPE50jjg2BOb9rp9OytG2ef1IdFtqFqMeY1A5u2ESGt/qQfjA97VSFO64xmpsKxK5CcMOJMtEGr+JQHDupvxpbOGrMhE3MWdQZg== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UNxvjwdXjTJcHYFreJM0nbv+SRwO6xEr6/vyMOPDePw=; b=AYeLehr7RbbO924uIPlWH2XPgdbfGEdyWjVPPeKvv7l42eS87DLQ7d78iylzTfS6nA6OVdFWO2hXFwykSRke7sIHmDsxqeuhOon7fOwfSk3HKbpNPUYRtuwIUvLBldRBo+bQiTCAhISSj/IoRT54v/7M27/DkPZVPokJCxRmQ44= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from SJ0PR12MB6760.namprd12.prod.outlook.com (2603:10b6:a03:44c::18) by MW6PR12MB8914.namprd12.prod.outlook.com (2603:10b6:303:244::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 15:30:56 +0000 Received: from SJ0PR12MB6760.namprd12.prod.outlook.com ([fe80::ae50:7a3a:dad3:1d04]) by SJ0PR12MB6760.namprd12.prod.outlook.com ([fe80::ae50:7a3a:dad3:1d04%6]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 15:30:55 +0000 Content-Type: multipart/alternative; boundary="------------r6JMQFiqU8GjVNCDoe98Nu1S" Message-ID: Date: Mon, 13 Nov 2023 10:30:53 -0500 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 22/24] drm/amdkfd: add pc sampling release when process release Content-Language: en-US To: "Yat Sin, David" , "Zhu, James" , "amd-gfx@lists.freedesktop.org" References: <20231103131139.766920-1-James.Zhu@amd.com> <20231103131139.766920-23-James.Zhu@amd.com> From: James Zhu Organization: AMD RTG In-Reply-To: X-ClientProxiedBy: QB1P288CA0022.CANP288.PROD.OUTLOOK.COM (2603:10b6:c00:2d::35) To SJ0PR12MB6760.namprd12.prod.outlook.com (2603:10b6:a03:44c::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR12MB6760:EE_|MW6PR12MB8914:EE_ X-MS-Office365-Filtering-Correlation-Id: 855993d4-4cd9-4da9-c2be-08dbe45d874a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fXK3GeFH2JEoZ8cv3T9+wanF6t/JJ5vEiukWfBdHujirQAWN5PVlv12LAR+Zo3ukHY2+FflraCnlKqxtrAZheaiCZlmMVHn0PQwzO/CxWprmup2sX/1pH0VcEfNbiRWQeiSMTtH6rDsuNP0vT301Nvrnt+TBrO83/FYoJBZANbY606fgwpb9h0BjciDZR2f8qpljwIyY6HrsgVHu9g1cOhF7gIiWI80rEFSeSUymye3ByD2RjJbfSY+G6vxGb/2hmvZFWky8jsGHWvlUJGI+e0SQnIyY7ZnhAgJlSoi83j+OmBNvuvnd2ckMEBtB+QuX+CqTorNRYzJ2VjdOxFrlSjJ4WInmqhQA5Etx8AJuvmqcqFgl6yQqahDenXe3xZTvwylr/8+BwK+Rm+67Qp9cxu7+4kUXoE08lmfehMQxdNCn5jzFVc7B3iOdwYvw+KIV8/TVRiVjpbWvX20rQE6sVqvjKr0hZK8fErS5G+OrYBWNmyXvoqRZOL6bH2xqHvvA6BxsuEI4y7PjKVuJvyHJ9hFC/oeLlIn9XxE7LcCCd4XJqrBiMM9JCeHlb4pfGKwPCnhNGVzP83R2mJ9gZwTH0qKWz+lm6Xgxs7Pq+RbqqnqwYK2Fy5F7D5NZUGAiqsekTR2gvZdPNe2j/+lr1CUwQQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR12MB6760.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(136003)(39860400002)(396003)(346002)(376002)(366004)(230922051799003)(451199024)(186009)(1800799009)(64100799003)(2906002)(2616005)(5660300002)(31696002)(41300700001)(26005)(4001150100001)(110136005)(54906003)(66556008)(66946007)(6512007)(66476007)(316002)(38100700002)(83380400001)(31686004)(36756003)(478600001)(6486002)(53546011)(36916002)(33964004)(6506007)(8676002)(4326008)(8936002)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?TkRZWFhZMWlsUWp4Z1dlZDl1ZW4wamY4UkdvajV0ZXphdUhTS29yRE4wcUZn?= =?utf-8?B?ZHlidmRwTytIdTRSU1ovWHQ3RDQ0QWNVRjBuQTlhNU5zTWs4VFJhVTNzZ2wz?= =?utf-8?B?Y3Z3VVlkNmFTaU5PSXVMV25IM0pZZG9qSXlMajd4VEJDTDl4S2xrTVJnaFZ5?= =?utf-8?B?T3hadVRTTDJLTG84Z2FXdnNOMzIwclFYNGhUbWFhWWFHL2hsOUdhUHdkNTZm?= =?utf-8?B?ZGlJN2VRbUdjeVdGUlVvU3g3NXhlaS8ybmEyRUdXN3c4R0k1RThEY1Y4NGdS?= =?utf-8?B?eG5kaEF3UzdXSTkyRFd1dFpLaj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8?Q?KmHrnnd52naaTH0eK7GuhE16p?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 855993d4-4cd9-4da9-c2be-08dbe45d874a X-MS-Exchange-CrossTenant-AuthSource: SJ0PR12MB6760.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 15:30:55.8351 (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: ldMrPP9EUCNRvYSKYIXICSVNi5lGd0syAWbQVga+av5Dy19jNNUR0/nWya+313yw X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8914 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: "Kuehling, Felix" , "Greathouse, Joseph" Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" --------------r6JMQFiqU8GjVNCDoe98Nu1S Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2023-11-13 10:19, Yat Sin, David wrote: > > [AMD Official Use Only - General] > > > *From:* Zhu, James > *Sent:* Monday, November 13, 2023 10:13 AM > *To:* Yat Sin, David ; Zhu, James > ; amd-gfx@lists.freedesktop.org > *Cc:* Kuehling, Felix ; Greathouse, Joseph > > *Subject:* Re: [PATCH 22/24] drm/amdkfd: add pc sampling release when > process release > > On 2023-11-10 14:08, Yat Sin, David wrote: > > [AMD Official Use Only - General] > > -----Original Message----- > > From: Zhu, James > > Sent: Friday, November 3, 2023 9:12 AM > > To:amd-gfx@lists.freedesktop.org > > Cc: Kuehling, Felix ; Greathouse, Joseph > > ; Yat Sin, David ; Zhu, > > James > > Subject: [PATCH 22/24] drm/amdkfd: add pc sampling release when process > > release > > Add pc sampling release when process release, it will force to stop all activate > > sessions with this process. > > Signed-off-by: James Zhu > > --- > > drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 26 > > ++++++++++++++++++++  drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h | > > 1 + > > drivers/gpu/drm/amd/amdkfd/kfd_process.c     |  3 +++ > > 3 files changed, 30 insertions(+) > > diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c > > b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c > > index 66670cdb813a..00d8d3f400a9 100644 > > --- a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c > > +++ b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c > > @@ -274,6 +274,32 @@ static int kfd_pc_sample_destroy(struct > > kfd_process_device *pdd, uint32_t trace_ > >       return 0; > > } > > +void kfd_pc_sample_release(struct kfd_process_device *pdd) { > > +     struct pc_sampling_entry *pcs_entry; > > +     struct idr *idp; > > +     uint32_t id; > > + > > +     if (sched_policy == KFD_SCHED_POLICY_NO_HWS) { > > +             pr_err("PC Sampling does not support sched_policy %i", > > sched_policy); > > +             return; > > +     } > > You do not need to check the sched_policy here, already checked in kfd_ioctl_pc_sample(..) , so cannot have a hosttrap session if policy is NO_HWS. > >   [JZ]kfd_pc_sample_release is not called from kfd_ioctl_pc_sample. It > is in process quit process. > > [David] I know. But you cannot have a PC sampling session during > process clean-up when policy=NO_HWS because the session creation would > have been blocked on session-create. > [JZ] good point. > > + > > +     /* force to release all PC sampling task for this process */ > > +     idp = &pdd->dev->pcs_data.hosttrap_entry.base.pc_sampling_idr; > > +     mutex_lock(&pdd->dev->pcs_data.mutex); > > +     idr_for_each_entry(idp, pcs_entry, id) { > > +             if (pcs_entry->pdd != pdd) > > +                     continue; > > +             mutex_unlock(&pdd->dev->pcs_data.mutex); > > Can we not release the mutex here and just tell the worker thread to exit by setting the stop_enable bit. > > I find we have a lot of places where we are acquiring/releasing the mutex within loops and this results in a > > lot of extra states that we have to account for during the start/stop/destroy calls. > > +             if (pcs_entry->enabled) > > +                     kfd_pc_sample_stop(pdd, pcs_entry); > > +             kfd_pc_sample_destroy(pdd, id, pcs_entry); > > +             mutex_lock(&pdd->dev->pcs_data.mutex); > > +     } > > +     mutex_unlock(&pdd->dev->pcs_data.mutex); > > +} > > + > > int kfd_pc_sample(struct kfd_process_device *pdd, > >                                       struct kfd_ioctl_pc_sample_args __user > > *args)  { diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h > > b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h > > index cb93909e6bd3..4ea064fdaa98 100644 > > --- a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h > > +++ b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h > > @@ -30,6 +30,7 @@ > > int kfd_pc_sample(struct kfd_process_device *pdd, > >                                       struct kfd_ioctl_pc_sample_args __user > > *args); > > +void kfd_pc_sample_release(struct kfd_process_device *pdd); > > void kfd_pc_sample_handler(struct work_struct *work); > > #endif /* KFD_PC_SAMPLING_H_ */ > > diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c > > b/drivers/gpu/drm/amd/amdkfd/kfd_process.c > > index d22d804f180d..54f3db7eaae2 100644 > > --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c > > +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c > > @@ -43,6 +43,7 @@ struct mm_struct; > > #include "kfd_svm.h" > > #include "kfd_smi_events.h" > > #include "kfd_debug.h" > > +#include "kfd_pc_sampling.h" > > /* > >   * List of struct kfd_process (field kfd_process). > > @@ -1020,6 +1021,8 @@ static void kfd_process_destroy_pdds(struct > > kfd_process *p) > >               pr_debug("Releasing pdd (topology id %d) for process (pasid > > 0x%x)\n", > >                               pdd->dev->id, p->pasid); > > +             kfd_pc_sample_release(pdd); > > + > >               kfd_process_device_destroy_cwsr_dgpu(pdd); > >               kfd_process_device_destroy_ib_mem(pdd); > > -- > > 2.25.1 > --------------r6JMQFiqU8GjVNCDoe98Nu1S Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 2023-11-13 10:19, Yat Sin, David wrote:

[AMD Official Use Only - General]


 

 

From: Zhu, James <James.Zhu@amd.com>
Sent: Monday, November 13, 2023 10:13 AM
To: Yat Sin, David <David.YatSin@amd.com>; Zhu, James <James.Zhu@amd.com>; amd-gfx@lists.freedesktop.org
Cc: Kuehling, Felix <Felix.Kuehling@amd.com>; Greathouse, Joseph <Joseph.Greathouse@amd.com>
Subject: Re: [PATCH 22/24] drm/amdkfd: add pc sampling release when process release

 

 

On 2023-11-10 14:08, Yat Sin, David wrote:

[AMD Official Use Only - General]
 
-----Original Message-----
From: Zhu, James <James.Zhu@amd.com>
Sent: Friday, November 3, 2023 9:12 AM
To: amd-gfx@lists.freedesktop.org
Cc: Kuehling, Felix <Felix.Kuehling@amd.com>; Greathouse, Joseph
<Joseph.Greathouse@amd.com>; Yat Sin, David <David.YatSin@amd.com>; Zhu,
James <James.Zhu@amd.com>
Subject: [PATCH 22/24] drm/amdkfd: add pc sampling release when process
release
 
Add pc sampling release when process release, it will force to stop all activate
sessions with this process.
 
Signed-off-by: James Zhu <James.Zhu@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 26
++++++++++++++++++++  drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h |
1 +
 drivers/gpu/drm/amd/amdkfd/kfd_process.c     |  3 +++
 3 files changed, 30 insertions(+)
 
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
index 66670cdb813a..00d8d3f400a9 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
@@ -274,6 +274,32 @@ static int kfd_pc_sample_destroy(struct
kfd_process_device *pdd, uint32_t trace_
      return 0;
 }
 
+void kfd_pc_sample_release(struct kfd_process_device *pdd) {
+     struct pc_sampling_entry *pcs_entry;
+     struct idr *idp;
+     uint32_t id;
+
+     if (sched_policy == KFD_SCHED_POLICY_NO_HWS) {
+             pr_err("PC Sampling does not support sched_policy %i",
sched_policy);
+             return;
+     }
You do not need to check the sched_policy here, already checked in kfd_ioctl_pc_sample(..) , so cannot have a hosttrap session if policy is NO_HWS.

  [JZ]kfd_pc_sample_release is not called from kfd_ioctl_pc_sample. It is in process quit process.

[David] I know. But you cannot have a PC sampling session during process clean-up when policy=NO_HWS because the session creation would have been blocked on session-create.

[JZ] good point.

+
+     /* force to release all PC sampling task for this process */
+     idp = &pdd->dev->pcs_data.hosttrap_entry.base.pc_sampling_idr;
+     mutex_lock(&pdd->dev->pcs_data.mutex);
+     idr_for_each_entry(idp, pcs_entry, id) {
+             if (pcs_entry->pdd != pdd)
+                     continue;
+             mutex_unlock(&pdd->dev->pcs_data.mutex);
Can we not release the mutex here and just tell the worker thread to exit by setting the stop_enable bit.
I find we have a lot of places where we are acquiring/releasing the mutex within loops and this results in a
lot of extra states that we have to account for during the start/stop/destroy calls.
+             if (pcs_entry->enabled)
+                     kfd_pc_sample_stop(pdd, pcs_entry);
+             kfd_pc_sample_destroy(pdd, id, pcs_entry);
+             mutex_lock(&pdd->dev->pcs_data.mutex);
+     }
+     mutex_unlock(&pdd->dev->pcs_data.mutex);
+}
+
 int kfd_pc_sample(struct kfd_process_device *pdd,
                                      struct kfd_ioctl_pc_sample_args __user
*args)  { diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h
b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h
index cb93909e6bd3..4ea064fdaa98 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h
@@ -30,6 +30,7 @@
 
 int kfd_pc_sample(struct kfd_process_device *pdd,
                                      struct kfd_ioctl_pc_sample_args __user
*args);
+void kfd_pc_sample_release(struct kfd_process_device *pdd);
 void kfd_pc_sample_handler(struct work_struct *work);
 
 #endif /* KFD_PC_SAMPLING_H_ */
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index d22d804f180d..54f3db7eaae2 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -43,6 +43,7 @@ struct mm_struct;
 #include "kfd_svm.h"
 #include "kfd_smi_events.h"
 #include "kfd_debug.h"
+#include "kfd_pc_sampling.h"
 
 /*
  * List of struct kfd_process (field kfd_process).
@@ -1020,6 +1021,8 @@ static void kfd_process_destroy_pdds(struct
kfd_process *p)
              pr_debug("Releasing pdd (topology id %d) for process (pasid
0x%x)\n",
                              pdd->dev->id, p->pasid);
 
+             kfd_pc_sample_release(pdd);
+
              kfd_process_device_destroy_cwsr_dgpu(pdd);
              kfd_process_device_destroy_ib_mem(pdd);
 
--
2.25.1
 
--------------r6JMQFiqU8GjVNCDoe98Nu1S--