From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEE3FC83029 for ; Mon, 30 Jun 2025 17:47:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F6BE6B00D3; Mon, 30 Jun 2025 13:47:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A6F26B00D4; Mon, 30 Jun 2025 13:47:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66EB16B00D5; Mon, 30 Jun 2025 13:47:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 51B096B00D3 for ; Mon, 30 Jun 2025 13:47:27 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2D7D51065A7 for ; Mon, 30 Jun 2025 17:47:27 +0000 (UTC) X-FDA: 83612798934.15.7B1E876 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by imf14.hostedemail.com (Postfix) with ESMTP id 25003100004 for ; Mon, 30 Jun 2025 17:47:24 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FH0ZfVdU; spf=pass (imf14.hostedemail.com: domain of suresh.k.chandrappa@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=suresh.k.chandrappa@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751305645; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PQRn9x8VzDYN4hd8czObLye76LL/ATFFk9dTEIgXFng=; b=5zEoUOQ+vwVuaFIgbVEvr0V4pd7Z6ThNeWOY54ouRlxKIfPRRfVviFBOm7UnXUOciF4h2T X3IhzLkkzXUGEdYbukkfBAiHfvVk1ZPT167Wl29pssc23xDRC0JGHtJ82c5UCh7itiDCzj iKLUVll+s+hvAfeMYU1yPGFu/pIjyRw= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FH0ZfVdU; spf=pass (imf14.hostedemail.com: domain of suresh.k.chandrappa@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=suresh.k.chandrappa@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751305645; a=rsa-sha256; cv=none; b=2dtQVCQMjEZzKQFWJIhGaY7VgTQ38nlT3qbyLKaxSqgJSKCN03quF3iwriSY0C2ILhNIT4 9HNzKNAmGn29qjX2cxp3mCMSSNvq1Nn+L3j9/4r18aYgKm0SGrEncGs5HI/opT3/1V1OdZ QTBbGJRc7HIvCSSHMoK23DSm9nLV29A= Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-451d3f72391so25632315e9.3 for ; Mon, 30 Jun 2025 10:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751305643; x=1751910443; darn=kvack.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=PQRn9x8VzDYN4hd8czObLye76LL/ATFFk9dTEIgXFng=; b=FH0ZfVdUhy6WKxjkQfN5bwGn36j2xXfQyenn4CPNUoGZ22gAgQuxOxzRb4FRagmX/L sdeF9GgqDgwivAFF1JqQ7na2grP54Xm+SWLdSL/eAFHI6CsPTS4dzkqw7+s8Tt2C3mSI hWHK55kuGCJnOak3zaMhJJCrGCoMvurgbegr5kvzT6Wgeys5SZlGtJv0tSoXw4Y4ZKrC Nea7xdbyOD4q5SjjSP0uWCq2yfLrRgB8o0PA2rrOClvZVvfvIXUN3chdii/pztZ4G1kU 3WgBAhJomic/7HUnDvPXJW2rgjgtel8j79gldeb12S4KcAyu8Z3RACz4kWmKaDcu7QHh 5LYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751305643; x=1751910443; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PQRn9x8VzDYN4hd8czObLye76LL/ATFFk9dTEIgXFng=; b=aTICZre4rD5OW5VBqeVMNR4ErjbyCbery+gcWHCgWfELyxOa55LV69JkPEJWk8Li/X njewISB8S/6N9SEcwYQWRxSiihrW5eM93Nj3xNS8hZ098N++6FTjFKN0aWjjCkx1mxcx 1m1S3dAPDunOBrDmj+J4kmu9v9XwgLytjJ6MfgFL9OBGyF+evGWh0lL07Wxu4jW4bQPv XlxB4BXFAvdXXxzWWQEixuzlW+6O5gnPdEte4XKaMdsH7F9Rlw1Suu9wQrHtM2940fuu hPoE9OloCxDToEycBNYv9f82YhuVbBf3w4VC7V7TvY/TCLGZcXNjb28Ui3WlU07dTOe7 19qw== X-Forwarded-Encrypted: i=1; AJvYcCUjc5mLeFsU8JQZyilAEqGhSvEBEg72DlMpriIc9lRZG3NfT79PUV+MgX+7m5haooCtPihQYbQfdg==@kvack.org X-Gm-Message-State: AOJu0YzS9+r058z+mjfZpkl5Z2vyeAuNGYf1p82NtAYYm9rSgIbIKZN3 dCPfVgtS3FROH/xEZ9e39BW5AoxF2SNUDd942fUepSeEsslQFRy4gmy/1FgfjmoY/XzkVCWS+5x mCPKZi2cfsB/sM0CGnglHYSnO4swg0Ts= X-Gm-Gg: ASbGncvBM90aQjHLVYox6S8FWcl0L1zl5FqbC2pZNJSlxogXFG3zEmU7DBjj0UGGKbh U5jNYP3ZB+AkI924p5ifAKAYOOrTbrzy9+6b1yJh5kdjQfJoEmkxEzeqRjRzs2ZwfLF57qbCxXy CJhdrYfL/ERdHQgBK02pprYmZvojMW5nOehW8ppBN7y59C X-Google-Smtp-Source: AGHT+IEbO7aC8HVvq68a7ygJVszylSk1jriyT1x6x2rfeea+UB/TzpfDE/6wGcohUjzUgjhb2KFSr8eihGpE9qSsGZ0= X-Received: by 2002:adf:9c8b:0:b0:3a0:a0d1:1131 with SMTP id ffacd0b85a97d-3a8f454923amr11033143f8f.7.1751305643418; Mon, 30 Jun 2025 10:47:23 -0700 (PDT) MIME-Version: 1.0 References: <20250611180936.12886-1-suresh.k.chandrappa@gmail.com> In-Reply-To: From: Suresh Chandrappa Date: Mon, 30 Jun 2025 23:17:12 +0530 X-Gm-Features: Ac12FXzy1L_vvYJ0j0Syohkw8ujgRm8TWpmvqplc3h8YC44FSyB5N_FuEIrPIoA Message-ID: Subject: Re: [PATCH v2] selftests: cachestat: Refactor test to remove duplication To: Nhat Pham Cc: hannes@cmpxchg.org, shuah@kernel.org, linux-mm@kvack.org Content-Type: multipart/alternative; boundary="000000000000c4e9130638cd9eb7" X-Stat-Signature: e7eutii89dqtp4o1es3914wxi9tfipjr X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 25003100004 X-Rspam-User: X-HE-Tag: 1751305644-463042 X-HE-Meta: U2FsdGVkX1+OGXDfCnaDylC1oDXLoSyFWsapVzVEURizGHSww9mo41qeZ552EvX640lC4/Km0FGEwopqNthoA0GKnRKFa2DZxfFYrUvwdXmbysSTRjyUq6RfvU3pE5D+o0FeMSwuf4cpQuFWOzTpafl4VrqwxGtCFRnp1eOdUxCr2GMQPXdGgjjiPKxoqr8BsqDB/cz3F0XVwElVBOrkXa3BIVQebYMewS7KstOfC8cpQ4hZVao5Wji7xeY9/jcWsQrDvf2qusXi5tHlf6nnX0zwnAtXYqh3MLiV5NB2PEmm1JhLyD1fmdVcs3SblhwE2NU0ibiUac4jgYYdSeV7M3VO4cX6zj9j+aoVOrZG1UdfNVB+ExATvRGTuYXOH6bA6YHGV/34FO4nvBWL7t0AHHYWCacd2TrSGoAsikstkFrWNwc+q4zDa6qB+w4VQ2oFfNA0+0zZEYgsc4hHhtO7ebIs4qKxDInlbllYVAOE5nD9cCuXXEE816ltD9moi9OPkYtGu/u8KbvyAwey7q3vnLadjnB+HCx1nIF8XhHraht4j8h0J5Y2m4tBO6Kt+BCaFx9JAI4A936fVQEVaMjmcgn9llgHYi9AWMBO6bPNh+Y8kVAWTCKewLHUf0jVbXIApHuLGKFOSxjQctgMo3GcbUHvMK8Seik2ff+g70DpnsOUZvoLM7fu5T03ZuY10SlPiMzKSCOUQGcstiNc+IUgmhOfoSRhR9lLtvRUEW8Ybf/a9mp71PY2uYVoJTAevdpQgdrQeXB1tQ9ALvpENw2Z1l9l4jitQ+nr/MJB/pZi+zBoL2ihz0T1Jzf4l+MM0WvPaG92l06C8HxvpseaA2dcbLy7qPJall0pXCZ12cXnBh3bFzxHgHvQrAMmEqRBYBNOtnR1CiT1SZKSgQn71pmm1JPUPsKEQHAC0w1c2PJeEjVb8imDaOfIxlKTCOE0SRLxpmJOC3cD4deuKNKDI7h 8vNCXdVf zKoWA3PobwKd4gy9tVXvRKDt7nR5k/Kn6/MkyyryRI2dwbPkk3goB31gzH+16wMylnLBN6A76bSls/Ge/XmQG966ZRKI5PZ/N3tbMs++SU56cjc0/xEjNgOJ+NWaOVVbSt7rZ7wPdumfOpLFLBk4TAD7tCqDSZ6FUE9vdrBVY2tlNMm3spo5V59qzRMBUo1OiHb6S6Xcm2OlxHLJwCBV43vigtkR6LyMzRTHGys8ARaQy9mvPTY9rWC1osxdrSwXblnS//eHDTi7mnFrDkwTx84kNvBMFZj/eYIWPkHyGnFS138MD/EH2l7bEvUIVE0CzzEPY0hd9yfEPcW/4lJgty9ic+ph/dzteXsuzCOe8dnT34pPGopAtSH6IxneBmDtyTFdF7h9XeuqCGDGI07vp50EdTQ8MlB1x9vqCEpTLl3W8n8yl+Mtpq+qB1x3wKTAut7wpaqaAiztlBpcshxwabykO+zTJ1tHdHerF X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: --000000000000c4e9130638cd9eb7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Nhat, >> -bool test_cachestat_shmem(void) >> +bool run_cachestat_test(enum file_type type) Can you just call this function test_cachestat(enum file_type type) ? We already have a function named *test_cachestat* that was introduced earlier in the codebase, so to avoid confusion or naming conflicts, I=E2=80= =99ve named this one run_cachestat_test On Mon, Jun 30, 2025 at 11:07=E2=80=AFPM Suresh Chandrappa < suresh.k.chandrappa@gmail.com> wrote: > Hi Nhat, > Sure i will squash them to a single patch and will share it. > > Thanks > Suresh K C > > On Fri, Jun 27, 2025 at 10:11=E2=80=AFPM Nhat Pham wr= ote: > >> On Tue, Jun 24, 2025 at 9:58=E2=80=AFPM Suresh Chandrappa >> wrote: >> > >> > Hi @nphamcs >> > Can you please check the modified change >> >> Is this supposed to be on top of the earlier patch you sent out? In >> that case, you should send both together as a patch series. >> >> > >> > Thanks >> > Suresh K C >> > >> > >> > On Wed, 11 Jun 2025, 23:39 Suresh K C, >> wrote: >> >> >> >> From: Suresh K C >> >> >> >> Refactored the mmap and shmem test logic into a common function >> >> to reduce code duplication and improve maintainability >> >> >> >> Changes in v2: >> >> Refactored mmap and shmem tests into a common function >> >> Renamed test function to run_cachestat_test() >> >> Removed test for /proc/cpuinfo as a general /proc test case >> already exists >> >> >> >> Signed-off-by: Suresh K C >> >> --- >> >> .../selftests/cachestat/test_cachestat.c | 97 ++++++-----------= -- >> >> 1 file changed, 30 insertions(+), 67 deletions(-) >> >> >> >> diff --git a/tools/testing/selftests/cachestat/test_cachestat.c >> b/tools/testing/selftests/cachestat/test_cachestat.c >> >> index 81e7f6dd2279..7c2f64175943 100644 >> >> --- a/tools/testing/selftests/cachestat/test_cachestat.c >> >> +++ b/tools/testing/selftests/cachestat/test_cachestat.c >> >> @@ -22,7 +22,7 @@ >> >> >> >> static const char * const dev_files[] =3D { >> >> "/dev/zero", "/dev/null", "/dev/urandom", >> >> - "/proc/version","/proc/cpuinfo","/proc" >> >> + "/proc/version","/proc" >> >> So you removed one file that you added in an earlier patch, right? >> Then why bother adding it in the first place...? >> >> Can you either: >> >> 1. Send the two patch together as a series. In the first patch, do not >> add /proc/cpuinfo. >> >> or >> >> 2. Squash them into a single patch. I'll let you decide if this is worth >> it. >> >> >> >> }; >> >> >> >> void print_cachestat(struct cachestat *cs) >> >> @@ -33,6 +33,11 @@ void print_cachestat(struct cachestat *cs) >> >> cs->nr_evicted, cs->nr_recently_evicted); >> >> } >> >> >> >> +enum file_type { >> >> + FILE_MMAP, >> >> + FILE_SHMEM >> >> +}; >> >> + >> >> bool write_exactly(int fd, size_t filesize) >> >> { >> >> int random_fd =3D open("/dev/urandom", O_RDONLY); >> >> @@ -202,66 +207,8 @@ static int test_cachestat(const char *filename, >> bool write_random, bool create, >> >> return ret; >> >> } >> >> >> >> -bool test_cachestat_mmap(void){ >> >> - >> >> - size_t PS =3D sysconf(_SC_PAGESIZE); >> >> - size_t filesize =3D PS * 512 * 2;; >> >> - int syscall_ret; >> >> - size_t compute_len =3D PS * 512; >> >> - struct cachestat_range cs_range =3D { PS, compute_len }; >> >> - char *filename =3D "tmpshmcstat"; >> >> - unsigned long num_pages =3D compute_len / PS; >> >> - struct cachestat cs; >> >> - bool ret =3D true; >> >> - int fd =3D open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666); >> >> - if (fd < 0) { >> >> - ksft_print_msg("Unable to create mmap file.\n"); >> >> - ret =3D false; >> >> - goto out; >> >> - } >> >> - if (ftruncate(fd, filesize)) { >> >> - ksft_print_msg("Unable to truncate mmap file.\n"); >> >> - ret =3D false; >> >> - goto close_fd; >> >> - } >> >> - if (!write_exactly(fd, filesize)) { >> >> - ksft_print_msg("Unable to write to mmap file.\n"); >> >> - ret =3D false; >> >> - goto close_fd; >> >> - } >> >> - char *map =3D mmap(NULL, filesize, PROT_READ | PROT_WRITE, >> MAP_SHARED, fd, 0); >> >> - if (map =3D=3D MAP_FAILED) { >> >> - ksft_print_msg("mmap failed.\n"); >> >> - ret =3D false; >> >> - goto close_fd; >> >> - } >> >> - >> >> - for (int i =3D 0; i < filesize; i++) { >> >> - map[i] =3D 'A'; >> >> - } >> >> - map[filesize - 1] =3D 'X'; >> >> - >> >> - syscall_ret =3D syscall(__NR_cachestat, fd, &cs_range, &cs, 0= ); >> >> - >> >> - if (syscall_ret) { >> >> - ksft_print_msg("Cachestat returned non-zero.\n"); >> >> - ret =3D false; >> >> - } else { >> >> - print_cachestat(&cs); >> >> - if (cs.nr_cache + cs.nr_evicted !=3D num_pages) { >> >> - ksft_print_msg("Total number of cached and >> evicted pages is off.\n"); >> >> - ret =3D false; >> >> - } >> >> - } >> >> - >> >> -close_fd: >> >> - close(fd); >> >> - unlink(filename); >> >> -out: >> >> - return ret; >> >> -} >> >> >> >> -bool test_cachestat_shmem(void) >> >> +bool run_cachestat_test(enum file_type type) >> >> Can you just call this function test_cachestat(enum file_type type) ? >> >> >> { >> >> size_t PS =3D sysconf(_SC_PAGESIZE); >> >> size_t filesize =3D PS * 512 * 2; /* 2 2MB huge pages */ >> >> @@ -271,27 +218,43 @@ bool test_cachestat_shmem(void) >> >> char *filename =3D "tmpshmcstat"; >> >> struct cachestat cs; >> >> bool ret =3D true; >> >> + int fd; >> >> unsigned long num_pages =3D compute_len / PS; >> >> - int fd =3D shm_open(filename, O_CREAT | O_RDWR, 0600); >> >> + if (type =3D=3D FILE_SHMEM) >> >> + fd =3D shm_open(filename, O_CREAT | O_RDWR, 0600); >> >> + else >> >> + fd =3D open(filename, O_RDWR | O_CREAT | O_TRUNC, 066= 6); >> >> >> >> if (fd < 0) { >> >> - ksft_print_msg("Unable to create shmem file.\n"); >> >> + ksft_print_msg("Unable to create file.\n"); >> >> ret =3D false; >> >> goto out; >> >> } >> >> >> >> if (ftruncate(fd, filesize)) { >> >> - ksft_print_msg("Unable to truncate shmem file.\n"); >> >> + ksft_print_msg("Unable to truncate file.\n"); >> >> ret =3D false; >> >> goto close_fd; >> >> } >> >> >> >> if (!write_exactly(fd, filesize)) { >> >> - ksft_print_msg("Unable to write to shmem file.\n"); >> >> + ksft_print_msg("Unable to write to file.\n"); >> >> ret =3D false; >> >> goto close_fd; >> >> } >> >> >> >> + if (type =3D=3D FILE_MMAP){ >> >> + char *map =3D mmap(NULL, filesize, PROT_READ | >> PROT_WRITE, MAP_SHARED, fd, 0); >> >> + if (map =3D=3D MAP_FAILED) { >> >> + ksft_print_msg("mmap failed.\n"); >> >> + ret =3D false; >> >> + goto close_fd; >> >> + } >> >> + for (int i =3D 0; i < filesize; i++) { >> >> + map[i] =3D 'A'; >> >> + } >> >> + map[filesize - 1] =3D 'X'; >> >> + } >> >> syscall_ret =3D syscall(__NR_cachestat, fd, &cs_range, &cs, 0= ); >> >> >> >> if (syscall_ret) { >> >> @@ -333,7 +296,7 @@ int main(void) >> >> ret =3D 1; >> >> } >> >> >> >> - for (int i =3D 0; i < 6; i++) { >> >> + for (int i =3D 0; i < 5; i++) { >> >> const char *dev_filename =3D dev_files[i]; >> >> >> >> if (test_cachestat(dev_filename, false, false, false, >> >> @@ -367,14 +330,14 @@ int main(void) >> >> break; >> >> } >> >> >> >> - if (test_cachestat_shmem()) >> >> + if (run_cachestat_test(FILE_SHMEM)) >> >> ksft_test_result_pass("cachestat works with a shmem >> file\n"); >> >> else { >> >> ksft_test_result_fail("cachestat fails with a shmem >> file\n"); >> >> ret =3D 1; >> >> } >> >> >> >> - if (test_cachestat_mmap()) >> >> + if (run_cachestat_test(FILE_MMAP)) >> >> ksft_test_result_pass("cachestat works with a mmap >> file\n"); >> >> else { >> >> ksft_test_result_fail("cachestat fails with a mmap >> file\n"); >> >> -- >> >> 2.43.0 >> >> >> > --000000000000c4e9130638cd9eb7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Nhat,

>> -bool test_cachestat_shmem(void)
&g= t;> +bool run_cachestat_test(enum file_type type)

Can you just call this function test_cachestat(enum fi= le_type type) ?

<= div>We already have a function named test_cachestat that was introdu= ced earlier in the codebase, so to avoid confusion or naming conflicts, I= =E2=80=99ve named this one run_cachestat_test


On Mon, Jun 30, 2025 at 11:07= =E2=80=AFPM Suresh Chandrappa <suresh.k.chandrappa@gmail.com> wrote:
Hi Nhat,
Sure i w= ill squash them to a single patch and will share it.

Thanks
Suresh K C

On Fri, Jun 27, 2025 at 10:11=E2=80=AFP= M Nhat Pham <npha= mcs@gmail.com> wrote:
On Tue, Jun 24, 2025 at 9:58=E2=80=AFPM Suresh Chandrappa
<sure= sh.k.chandrappa@gmail.com> wrote:
>
> Hi @nphamcs
> Can you please check the modified change

Is this supposed to be on top of the earlier patch you sent out? In
that case, you should send both together as a patch series.

>
> Thanks
> Suresh K C
>
>
> On Wed, 11 Jun 2025, 23:39 Suresh K C, <suresh.k.chandrappa@gmail.com&g= t; wrote:
>>
>> From: Suresh K C <suresh.k.chandrappa@gmail.com>
>>
>> Refactored the mmap and shmem test logic into a common function >> to reduce code duplication and improve maintainability
>>
>> Changes in v2:
>>=C2=A0 =C2=A0 =C2=A0Refactored mmap and shmem tests into a common f= unction
>>=C2=A0 =C2=A0 =C2=A0Renamed test function to run_cachestat_test() >>=C2=A0 =C2=A0 =C2=A0Removed test for /proc/cpuinfo as a general /pr= oc test case already exists
>>
>> Signed-off-by: Suresh K C <suresh.k.chandrappa@gmail.com>
>> ---
>>=C2=A0 .../selftests/cachestat/test_cachestat.c=C2=A0 =C2=A0 =C2=A0= | 97 ++++++-------------
>>=C2=A0 1 file changed, 30 insertions(+), 67 deletions(-)
>>
>> diff --git a/tools/testing/selftests/cachestat/test_cachestat.c b/= tools/testing/selftests/cachestat/test_cachestat.c
>> index 81e7f6dd2279..7c2f64175943 100644
>> --- a/tools/testing/selftests/cachestat/test_cachestat.c
>> +++ b/tools/testing/selftests/cachestat/test_cachestat.c
>> @@ -22,7 +22,7 @@
>>
>>=C2=A0 static const char * const dev_files[] =3D {
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"/dev/zero", "/dev= /null", "/dev/urandom",
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0"/proc/version","/proc/= cpuinfo","/proc"
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0"/proc/version","/proc&= quot;

So you removed one file that you added in an earlier patch, right?
Then why bother adding it in the first place...?

Can you either:

1. Send the two patch together as a series. In the first patch, do not
add /proc/cpuinfo.

or

2. Squash them into a single patch. I'll let you decide if this is wort= h it.


>>=C2=A0 };
>>
>>=C2=A0 void print_cachestat(struct cachestat *cs)
>> @@ -33,6 +33,11 @@ void print_cachestat(struct cachestat *cs)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cs->nr_evicted, cs->nr_rece= ntly_evicted);
>>=C2=A0 }
>>
>> +enum file_type {
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0FILE_MMAP,
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0FILE_SHMEM
>> +};
>> +
>>=C2=A0 bool write_exactly(int fd, size_t filesize)
>>=C2=A0 {
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int random_fd =3D open("/dev= /urandom", O_RDONLY);
>> @@ -202,66 +207,8 @@ static int test_cachestat(const char *filenam= e, bool write_random, bool create,
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return ret;
>>=C2=A0 }
>>
>> -bool test_cachestat_mmap(void){
>> -
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0size_t PS =3D sysconf(_SC_PAGESIZE); >> -=C2=A0 =C2=A0 =C2=A0 =C2=A0size_t filesize =3D PS * 512 * 2;;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0int syscall_ret;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0size_t compute_len =3D PS * 512;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0struct cachestat_range cs_range =3D { = PS, compute_len };
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0char *filename =3D "tmpshmcstat&q= uot;;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long num_pages =3D compute_le= n / PS;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0struct cachestat cs;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0bool ret =3D true;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0int fd =3D open(filename, O_RDWR | O_C= REAT | O_TRUNC, 0666);
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (fd < 0) {
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_print= _msg("Unable to create mmap file.\n");
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D fa= lse;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto out;<= br> >> -=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ftruncate(fd, filesize)) {
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_print= _msg("Unable to truncate mmap file.\n");
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D fa= lse;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto close= _fd;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!write_exactly(fd, filesize)) { >> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_print= _msg("Unable to write to mmap file.\n");
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D fa= lse;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto close= _fd;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0char *map =3D mmap(NULL, filesize, PRO= T_READ | PROT_WRITE, MAP_SHARED, fd, 0);
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (map =3D=3D MAP_FAILED) {
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_print= _msg("mmap failed.\n");
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D fa= lse;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto close= _fd;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> -
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0for (int i =3D 0; i < filesize; i++= ) {
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0map[i] =3D= 'A';
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0map[filesize - 1] =3D 'X';
>> -
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0syscall_ret =3D syscall(__NR_cachestat= , fd, &cs_range, &cs, 0);
>> -
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (syscall_ret) {
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_print= _msg("Cachestat returned non-zero.\n");
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D fa= lse;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0} else {
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0print_cach= estat(&cs);
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (cs.nr_= cache + cs.nr_evicted !=3D num_pages) {
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0ksft_print_msg("Total number of cached and evicted= pages is off.\n");
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0ret =3D false;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> -
>> -close_fd:
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0close(fd);
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0unlink(filename);
>> -out:
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0return ret;
>> -}
>>
>> -bool test_cachestat_shmem(void)
>> +bool run_cachestat_test(enum file_type type)

Can you just call this function test_cachestat(enum file_type type) ?

>>=C2=A0 {
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0size_t PS =3D sysconf(_SC_PAGESIZ= E);
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0size_t filesize =3D PS * 512 * 2;= /* 2 2MB huge pages */
>> @@ -271,27 +218,43 @@ bool test_cachestat_shmem(void)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0char *filename =3D "tmpshmcs= tat";
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct cachestat cs;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0bool ret =3D true;
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0int fd;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long num_pages =3D compu= te_len / PS;
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0int fd =3D shm_open(filename, O_CREAT = | O_RDWR, 0600);
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (type =3D=3D FILE_SHMEM)
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fd =3D shm= _open(filename, O_CREAT | O_RDWR, 0600);
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0else
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fd =3D ope= n(filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
>>
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (fd < 0) {
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_print= _msg("Unable to create shmem file.\n");
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_print= _msg("Unable to create file.\n");
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret = =3D false;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto = out;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>>
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (ftruncate(fd, filesize)) { >> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_print= _msg("Unable to truncate shmem file.\n");
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_print= _msg("Unable to truncate file.\n");
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret = =3D false;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto = close_fd;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>>
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!write_exactly(fd, filesize))= {
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_print= _msg("Unable to write to shmem file.\n");
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_print= _msg("Unable to write to file.\n");
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret = =3D false;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto = close_fd;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>>
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (type =3D=3D FILE_MMAP){
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0char *map = =3D mmap(NULL, filesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (map = =3D=3D MAP_FAILED) {
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0ksft_print_msg("mmap failed.\n");
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0ret =3D false;
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0goto close_fd;
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for (int i= =3D 0; i < filesize; i++) {
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0map[i] =3D 'A';
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0map[filesi= ze - 1] =3D 'X';
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0syscall_ret =3D syscall(__NR_cach= estat, fd, &cs_range, &cs, 0);
>>
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (syscall_ret) {
>> @@ -333,7 +296,7 @@ int main(void)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret = =3D 1;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>>
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0for (int i =3D 0; i < 6; i++) {
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0for (int i =3D 0; i < 5; i++) {
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0const= char *dev_filename =3D dev_files[i];
>>
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (t= est_cachestat(dev_filename, false, false, false,
>> @@ -367,14 +330,14 @@ int main(void)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break= ;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>>
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (test_cachestat_shmem())
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (run_cachestat_test(FILE_SHMEM)) >>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_= test_result_pass("cachestat works with a shmem file\n");
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0else {
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_= test_result_fail("cachestat fails with a shmem file\n");
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret = =3D 1;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>>
>> -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (test_cachestat_mmap())
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (run_cachestat_test(FILE_MMAP))
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_= test_result_pass("cachestat works with a mmap file\n");
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0else {
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_= test_result_fail("cachestat fails with a mmap file\n");
>> --
>> 2.43.0
>>
--000000000000c4e9130638cd9eb7--