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 8D65CC4332F for ; Mon, 13 Nov 2023 15:12:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0D2CA10E399; Mon, 13 Nov 2023 15:12:44 +0000 (UTC) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2087.outbound.protection.outlook.com [40.107.243.87]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2ED1210E380 for ; Mon, 13 Nov 2023 15:12:41 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OFRRFwfcLHoje39wmZu+FRKXxOWtrskL+LmQsV29dPhYcfyMPNnJ+hcT8N7CiwBYFHEoT0HsnriW3vhiLPI8lH87KUkSZ4MKh6mfGgeMjl5ac8Z/zAeeqfoDcTz+4JrmXsztNz6CKidLTPsLdQiTF68ajyuFGfWTSfziTtFMkAgiptAv1TufqutBcdEvP4dMJa2cQxXu7cvbVVTsoJnJKCww4Xvhz6OvF0qFqep6jB4uNu6zcJ6Q1u7wk8RSgtHDKnsa0CdzVweHbfAE+5R3v4rp24NC4JpD3QwIBSIwT/v7XeulHDF5TdacxZq6ySoAhRP+RaVfMiCqbE+RFtVLPA== 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=olvQzRj6omJMB+PNLWASzQ//QCmZEZ3wnPmsBNb/bXA=; b=kUJpKFLUaE7/PU9wNp1kO4mCiKKzbEvEdRCqF1H2RcTltCqt6YAF/kQP/qEwWs+lZDOcnGb6yilP3Q6PZ2CnsrPOjSHCg9xxlSWyxRgHNUqHYiI94C6KqyR/AMAm/N1duOc4WxAPW8uiezJaPAg3C3mC5jBV4jgdQlNjD+begaWV7BWHgd7F9ufr0bdti2lP3U/RNP5al73H8852aK5IIJftdM8x4mFSQzKx2lWXu8SJ2prvRcblTFKxWsOVChWHVAz3Jgpc5HRzU99tjZP7aWyyeFTdyxxlh9sPbFmEjkeo0Z4K9gIbeVsYeLdkaGffZdkyXrIqsGppc9NGm9/wAg== 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=olvQzRj6omJMB+PNLWASzQ//QCmZEZ3wnPmsBNb/bXA=; b=EE/SGTdqzxZAM0D0Eoxdj8ObOlbbL2JligKGQbxLZZe2AWTcZZGt0rmhKqYb1/1DR+Xi4xU+0edq+fP3MTIrerT9SF7eza0AMBQlIfd5yrPk8LpzOiEISWAnfAgduTWMBIeoLgz3doQY+p1/CnVtdOLzfDNeO1dRQpIXOjKunOo= 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 PH0PR12MB8052.namprd12.prod.outlook.com (2603:10b6:510:28b::18) 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:12:38 +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:12:38 +0000 Content-Type: multipart/alternative; boundary="------------CaAhPO3ocUrS06FsRIaXjWyH" Message-ID: Date: Mon, 13 Nov 2023 10:12:35 -0500 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 22/24] drm/amdkfd: add pc sampling release when process release 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> Content-Language: en-US From: James Zhu Organization: AMD RTG In-Reply-To: X-ClientProxiedBy: YQBPR0101CA0328.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:6c::20) To SJ0PR12MB6760.namprd12.prod.outlook.com (2603:10b6:a03:44c::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR12MB6760:EE_|PH0PR12MB8052:EE_ X-MS-Office365-Filtering-Correlation-Id: cbfb0dd4-74b8-4a30-a08f-08dbe45af93c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KOSMdzBHopVULheZ9P5vOwqHCEIuFQsR+844UreJ1hD7kjge+SFczSG+oi4YVEY3VK2xJUc72rigHPOh3l+voj5zmRtNDenqMq+Z6KkdBN/IJEcC0Bs5XdzlDUTOR3YQulC6EFEIzRvQUORLq2pCH+Oxsvi8ltSr0NgPKnQWtkkPxrcBqpTjyadQMgD3otBj8dNy8oRWRXw3uGxkFsVem4V2RxILTUiiC50fAeRA5DbbyaapX8CnaXdAJy08ulxyAPse8xVQx6CalUfYfbufGhUakpz1mRkfJ4vBxCryZ0qfEXc3wxE/ivWYsKh6nJ6KiIBZWw7SuVWzmHEsl8KMGVrN8HwThwS6GCellroRHjvbF1RY1aUxOOsK+Ewo0d1sj+sg+opfdUoEoWWv3NFrhL53Q+I0xmXsYmOxgOobfhvmTYPH2qCBsYrhGLUhkFpcvEjFp/7HZmWPWWb9yCz2UtjILO13P3fGBANiWXRrXqIRi4avl4mDQ5UIimV+TlO7o7LF3EkPtrxe2kbOcWL7sSueNI/nlFDDcLmqoR7xGNuw2DBqLKr8yKVEM4VDBaw7ttXUUJM+pHDrsSm6xERAKmFBwkfQN5yF1ruJvJd7f0hFqIT86smX7ixxpo/18OCD1EiE0YnjhvvhGuC1TcOjcA== 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)(396003)(39860400002)(376002)(136003)(346002)(366004)(230922051799003)(451199024)(186009)(64100799003)(1800799009)(26005)(36916002)(33964004)(6506007)(53546011)(6666004)(2616005)(6512007)(83380400001)(5660300002)(4326008)(8936002)(8676002)(2906002)(41300700001)(4001150100001)(6486002)(478600001)(316002)(110136005)(54906003)(66476007)(66946007)(66556008)(36756003)(31696002)(38100700002)(31686004)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Z21LUzVWSEQxbGFwQmNFOEREczlzaDJtUWdJQjUwQ2NpMkZGR21SbkE5SDBx?= =?utf-8?B?NHdiRDdRZGVmczFCL05DZ1N1aTE1QnJoNmVPQnAwWGJMS2hwYzNwblZIYktT?= =?utf-8?B?Q1E5QVVxeW54RGl1R2UrazNFemZYMTZJazNobG1aSjVhSmRBTkhlcngzeTF3?= =?utf-8?B?QndHbXQxK2FoY0JSbWY3ZHBSUjJic3BTUkxLcUU4THRPTXFBMjZjZlJ3T09S?= =?utf-8?B?cjJCUlkvMkt3eGNzSTRmM2RBdEZkY0N4ZmVsc2lhRDZnN3plbkpNWVBqVmJN?= =?utf-8?B?aHFrdGFCSUNBTW8z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nhCSGJ3?= =?utf-8?Q?7Klz+ADHHcL2IhQIv0AMLBXjV?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cbfb0dd4-74b8-4a30-a08f-08dbe45af93c 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:12:38.5094 (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: M2fofbuwV8N92jt6XpERYVZCXsB7FO59Ok8DMvQypzQFudhctNCtGv8NIuYx5mhW X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8052 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" --------------CaAhPO3ocUrS06FsRIaXjWyH Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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. >> + >> + /* 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 --------------CaAhPO3ocUrS06FsRIaXjWyH Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit


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.

      
+
+     /* 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

    
--------------CaAhPO3ocUrS06FsRIaXjWyH--