From: Shivank Garg <shivankg@amd.com>
To: <akpm@linux-foundation.org>, <david@redhat.com>
Cc: <ziy@nvidia.com>, <willy@infradead.org>,
<matthew.brost@intel.com>, <joshua.hahnjy@gmail.com>,
<rakie.kim@sk.com>, <byungchul@sk.com>, <gourry@gourry.net>,
<ying.huang@linux.alibaba.com>, <apopple@nvidia.com>,
<lorenzo.stoakes@oracle.com>, <Liam.Howlett@oracle.com>,
<vbabka@suse.cz>, <rppt@kernel.org>, <surenb@google.com>,
<mhocko@suse.com>, <vkoul@kernel.org>, <lucas.demarchi@intel.com>,
<rdunlap@infradead.org>, <jgg@ziepe.ca>, <kuba@kernel.org>,
<justonli@chromium.org>, <ivecera@redhat.com>,
<dave.jiang@intel.com>, <Jonathan.Cameron@huawei.com>,
<dan.j.williams@intel.com>, <rientjes@google.com>,
<Raghavendra.KodsaraThimmappa@amd.com>, <bharata@amd.com>,
<shivankg@amd.com>, <alirad.malek@zptcorp.com>,
<yiannis@zptcorp.com>, <weixugc@google.com>,
<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>
Subject: [RFC V3 9/9] mtcopy: spread threads across die for testing
Date: Tue, 23 Sep 2025 17:47:44 +0000 [thread overview]
Message-ID: <20250923174752.35701-10-shivankg@amd.com> (raw)
In-Reply-To: <20250923174752.35701-1-shivankg@amd.com>
Select CPUs using sysfs
For testing purpose only.
Signed-off-by: Shivank Garg <shivankg@amd.com>
---
drivers/migoffcopy/mtcopy/copy_pages.c | 76 +++++++++++++++++++++++++-
1 file changed, 73 insertions(+), 3 deletions(-)
diff --git a/drivers/migoffcopy/mtcopy/copy_pages.c b/drivers/migoffcopy/mtcopy/copy_pages.c
index 68e50de602d6..e605acca39d0 100644
--- a/drivers/migoffcopy/mtcopy/copy_pages.c
+++ b/drivers/migoffcopy/mtcopy/copy_pages.c
@@ -15,11 +15,37 @@
#include <linux/migrate.h>
#include <linux/migrate_offc.h>
-#define MAX_NUM_COPY_THREADS 64
+#define MAX_NUM_COPY_THREADS 32
unsigned int limit_mt_num = 4;
static int is_dispatching;
+static int cpuselect;
+
+// spread across die
+static const int cpu_id_list_0[] = {
+ 0, 8, 16, 24,
+ 32, 40, 48, 56,
+ 64, 72, 80, 88,
+ 96, 104, 112, 120,
+ 128, 136, 144, 152,
+ 160, 168, 176, 184,
+ 192, 200, 208, 216,
+ 224, 232, 240, 248};
+
+// don't spread, fill the die
+static const int cpu_id_list_1[] = {
+ 0, 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, 9, 10, 11,
+ 12, 13, 14, 15,
+ 16, 17, 18, 19,
+ 20, 21, 22, 23,
+ 24, 25, 26, 27,
+ 28, 29, 30, 31};
+
+int cpu_id_list[32] = {0};
+
static int copy_page_lists_mt(struct list_head *dst_folios,
struct list_head *src_folios, unsigned int nr_items);
@@ -141,6 +167,39 @@ static ssize_t mt_threads_show(struct kobject *kobj,
return sysfs_emit(buf, "%u\n", limit_mt_num);
}
+static ssize_t mt_cpuselect_set(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ int ccode;
+ unsigned int cpuconfig;
+
+ ccode = kstrtouint(buf, 0, &cpuconfig);
+ if (ccode) {
+ pr_debug("(%s:) error parsing input %s\n", __func__, buf);
+ return ccode;
+ }
+ mutex_lock(&migratecfg_mutex);
+ cpuselect = cpuconfig;
+ switch (cpuselect) {
+ case 1:
+ memcpy(cpu_id_list, cpu_id_list_1, MAX_NUM_COPY_THREADS*sizeof(int));
+ break;
+ default:
+ memcpy(cpu_id_list, cpu_id_list_0, MAX_NUM_COPY_THREADS*sizeof(int));
+ break;
+ }
+
+ mutex_unlock(&migratecfg_mutex);
+
+ return count;
+}
+
+static ssize_t mt_cpuselect_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ return sysfs_emit(buf, "%u\n", cpuselect);
+}
+
int copy_page_lists_mt(struct list_head *dst_folios,
struct list_head *src_folios, unsigned int nr_items)
{
@@ -208,7 +267,7 @@ int copy_page_lists_mt(struct list_head *dst_folios,
}
for (cpu = 0; cpu < total_mt_num; ++cpu)
- queue_work(system_unbound_wq,
+ queue_work_on(cpu_id_list[cpu], system_unbound_wq,
(struct work_struct *)work_items[cpu]);
} else {
int num_xfer_per_thread = nr_items / total_mt_num;
@@ -245,7 +304,7 @@ int copy_page_lists_mt(struct list_head *dst_folios,
dst2 = list_next_entry(dst, lru);
if (per_cpu_item_idx == work_items[cpu]->num_items) {
- queue_work(system_unbound_wq,
+ queue_work_on(cpu_id_list[cpu], system_unbound_wq,
(struct work_struct *)work_items[cpu]);
per_cpu_item_idx = 0;
cpu++;
@@ -276,6 +335,8 @@ static struct kobj_attribute mt_offloading_attribute = __ATTR(offloading, 0664,
mt_offloading_show, mt_offloading_set);
static struct kobj_attribute mt_threads_attribute = __ATTR(threads, 0664,
mt_threads_show, mt_threads_set);
+static struct kobj_attribute mt_cpuselect_attribute = __ATTR(cpuselect, 0664,
+ mt_cpuselect_show, mt_cpuselect_set);
static int __init cpu_mt_module_init(void)
{
@@ -293,10 +354,18 @@ static int __init cpu_mt_module_init(void)
if (ret)
goto out_threads;
+ ret = sysfs_create_file(mt_kobj_ref, &mt_cpuselect_attribute.attr);
+ if (ret)
+ goto out_cpuselect;
+
+ memcpy(cpu_id_list, cpu_id_list_0, MAX_NUM_COPY_THREADS*sizeof(int));
+
is_dispatching = 0;
return 0;
+out_cpuselect:
+ sysfs_remove_file(mt_kobj_ref, &mt_threads_attribute.attr);
out_threads:
sysfs_remove_file(mt_kobj_ref, &mt_offloading_attribute.attr);
out_offloading:
@@ -314,6 +383,7 @@ static void __exit cpu_mt_module_exit(void)
}
mutex_unlock(&migratecfg_mutex);
+ sysfs_remove_file(mt_kobj_ref, &mt_cpuselect_attribute.attr);
sysfs_remove_file(mt_kobj_ref, &mt_threads_attribute.attr);
sysfs_remove_file(mt_kobj_ref, &mt_offloading_attribute.attr);
kobject_put(mt_kobj_ref);
--
2.43.0
next prev parent reply other threads:[~2025-09-23 17:50 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-23 17:47 [RFC V3 0/9] Accelerate page migration with batch copying and hardware offload Shivank Garg
2025-09-23 17:47 ` [RFC V3 1/9] mm/migrate: factor out code in move_to_new_folio() and migrate_folio_move() Shivank Garg
2025-10-02 10:30 ` Jonathan Cameron
2025-09-23 17:47 ` [RFC V3 2/9] mm/migrate: revive MIGRATE_NO_COPY in migrate_mode Shivank Garg
2025-09-23 17:47 ` [RFC V3 3/9] mm: Introduce folios_mc_copy() for batch copying folios Shivank Garg
2025-09-23 17:47 ` [RFC V3 4/9] mm/migrate: add migrate_folios_batch_move to batch the folio move operations Shivank Garg
2025-10-02 11:03 ` Jonathan Cameron
2025-10-16 9:17 ` Garg, Shivank
2025-09-23 17:47 ` [RFC V3 5/9] mm: add support for copy offload for folio Migration Shivank Garg
2025-10-02 11:10 ` Jonathan Cameron
2025-10-16 9:40 ` Garg, Shivank
2025-09-23 17:47 ` [RFC V3 6/9] mtcopy: introduce multi-threaded page copy routine Shivank Garg
2025-10-02 11:29 ` Jonathan Cameron
2025-10-20 8:28 ` Byungchul Park
2025-11-06 6:27 ` Garg, Shivank
2025-11-12 2:12 ` Byungchul Park
2025-09-23 17:47 ` [RFC V3 7/9] dcbm: add dma core batch migrator for batch page offloading Shivank Garg
2025-10-02 11:38 ` Jonathan Cameron
2025-10-16 9:59 ` Garg, Shivank
2025-09-23 17:47 ` [RFC V3 8/9] adjust NR_MAX_BATCHED_MIGRATION for testing Shivank Garg
2025-09-23 17:47 ` Shivank Garg [this message]
2025-09-24 1:49 ` [RFC V3 0/9] Accelerate page migration with batch copying and hardware offload Huang, Ying
2025-09-24 2:03 ` Zi Yan
2025-09-24 3:11 ` Huang, Ying
2025-09-24 3:22 ` Zi Yan
2025-10-02 17:10 ` Garg, Shivank
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250923174752.35701-10-shivankg@amd.com \
--to=shivankg@amd.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=Liam.Howlett@oracle.com \
--cc=Raghavendra.KodsaraThimmappa@amd.com \
--cc=akpm@linux-foundation.org \
--cc=alirad.malek@zptcorp.com \
--cc=apopple@nvidia.com \
--cc=bharata@amd.com \
--cc=byungchul@sk.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=david@redhat.com \
--cc=gourry@gourry.net \
--cc=ivecera@redhat.com \
--cc=jgg@ziepe.ca \
--cc=joshua.hahnjy@gmail.com \
--cc=justonli@chromium.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=lucas.demarchi@intel.com \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=rakie.kim@sk.com \
--cc=rdunlap@infradead.org \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=vkoul@kernel.org \
--cc=weixugc@google.com \
--cc=willy@infradead.org \
--cc=yiannis@zptcorp.com \
--cc=ying.huang@linux.alibaba.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox