Skip to content

Commit fd1d882

Browse files
terminusacmel
authored andcommitted
perf bench mem: Allow chunking on a memory region
There can be a significant gap in memset/memcpy performance depending on the size of the region being operated on. With chunk-size=4kb: $ echo madvise > /sys/kernel/mm/transparent_hugepage/enabled $ perf bench mem memset -p 4kb -k 4kb -s 4gb -l 10 -f x86-64-stosq # Running 'mem/memset' benchmark: # function 'x86-64-stosq' (movsq-based memset() in arch/x86/lib/memset_64.S) # Copying 4gb bytes ... 13.011655 GB/sec With chunk-size=1gb: $ echo madvise > /sys/kernel/mm/transparent_hugepage/enabled $ perf bench mem memset -p 4kb -k 1gb -s 4gb -l 10 -f x86-64-stosq # Running 'mem/memset' benchmark: # function 'x86-64-stosq' (movsq-based memset() in arch/x86/lib/memset_64.S) # Copying 4gb bytes ... 21.936355 GB/sec So, allow the user to specify the chunk-size. The default value is identical to the total size of the region, which preserves current behaviour. Reviewed-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: David Hildenbrand <david@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Mateusz Guzik <mjguzik@gmail.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Raghavendra K T <raghavendra.kt@amd.com> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 7b6837e commit fd1d882

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

tools/perf/Documentation/perf-bench.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ Available units are B, KB, MB, GB and TB (case insensitive).
187187
Specify page-size for mapping memory buffers (default: 4KB).
188188
Available values are 4KB, 2MB, 1GB (case insensitive).
189189

190+
-k::
191+
--chunk::
192+
Specify the chunk-size for each invocation. (default: 0, or full-extent)
193+
Available units are B, KB, MB, GB and TB (case insensitive).
194+
190195
-f::
191196
--function::
192197
Specify function to copy (default: default).
@@ -216,6 +221,11 @@ Available units are B, KB, MB, GB and TB (case insensitive).
216221
Specify page-size for mapping memory buffers (default: 4KB).
217222
Available values are 4KB, 2MB, 1GB (case insensitive).
218223

224+
-k::
225+
--chunk::
226+
Specify the chunk-size for each invocation. (default: 0, or full-extent)
227+
Available units are B, KB, MB, GB and TB (case insensitive).
228+
219229
-f::
220230
--function::
221231
Specify function to set (default: default).

tools/perf/bench/mem-functions.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
static const char *size_str = "1MB";
3737
static const char *function_str = "all";
3838
static const char *page_size_str = "4KB";
39+
static const char *chunk_size_str = "0";
3940
static unsigned int nr_loops = 1;
4041
static bool use_cycles;
4142
static int cycles_fd;
@@ -49,6 +50,10 @@ static const struct option options[] = {
4950
"Specify page-size for mapping memory buffers. "
5051
"Available sizes: 4KB, 2MB, 1GB (case insensitive)"),
5152

53+
OPT_STRING('k', "chunk", &chunk_size_str, "0",
54+
"Specify the chunk-size for each invocation. "
55+
"Available units: B, KB, MB, GB and TB (case insensitive)"),
56+
5257
OPT_STRING('f', "function", &function_str, "all",
5358
"Specify the function to run, \"all\" runs all available functions, \"help\" lists them"),
5459

@@ -69,6 +74,7 @@ union bench_clock {
6974
struct bench_params {
7075
size_t size;
7176
size_t size_total;
77+
size_t chunk_size;
7278
unsigned int nr_loops;
7379
unsigned int page_shift;
7480
};
@@ -243,6 +249,14 @@ static int bench_mem_common(int argc, const char **argv, struct bench_mem_info *
243249
}
244250
p.size_total = p.size * p.nr_loops;
245251

252+
p.chunk_size = (size_t)perf_atoll((char *)chunk_size_str);
253+
if ((s64)p.chunk_size < 0 || (s64)p.chunk_size > (s64)p.size) {
254+
fprintf(stderr, "Invalid chunk_size:%s\n", chunk_size_str);
255+
return 1;
256+
}
257+
if (!p.chunk_size)
258+
p.chunk_size = p.size;
259+
246260
page_size = (unsigned int)perf_atoll((char *)page_size_str);
247261
if (page_size != (1 << PAGE_SHIFT_4KB) &&
248262
page_size != (1 << PAGE_SHIFT_2MB) &&
@@ -300,7 +314,8 @@ static int do_memcpy(const struct function *r, struct bench_params *p,
300314

301315
clock_get(&start);
302316
for (unsigned int i = 0; i < p->nr_loops; ++i)
303-
fn(dst, src, p->size);
317+
for (size_t off = 0; off < p->size; off += p->chunk_size)
318+
fn(dst + off, src + off, min(p->chunk_size, p->size - off));
304319
clock_get(&end);
305320

306321
*rt = clock_diff(&start, &end);
@@ -402,7 +417,8 @@ static int do_memset(const struct function *r, struct bench_params *p,
402417

403418
clock_get(&start);
404419
for (unsigned int i = 0; i < p->nr_loops; ++i)
405-
fn(dst, i, p->size);
420+
for (size_t off = 0; off < p->size; off += p->chunk_size)
421+
fn(dst + off, i, min(p->chunk_size, p->size - off));
406422
clock_get(&end);
407423

408424
*rt = clock_diff(&start, &end);

0 commit comments

Comments
 (0)