public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Avinesh Kumar <akumar@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] msync01: Rewrite using new LTP API
Date: Wed, 21 Feb 2024 15:04:59 +0100	[thread overview]
Message-ID: <ZdYDC7m7xJ_MbXR3@yuki> (raw)
In-Reply-To: <20240219153012.3085-1-akumar@suse.de>

Hi!
> -/*
> - * setup() - performs all ONE TIME setup for this test.
> - *
> - * Get system page size,
> - * Creat a temporary directory and a file under it used for mapping.
> - * Write 1 page size char data into file.
> - * Initialize paged region (256 bytes) from the specified offset pos.
> - */
> -void setup(void)
> +static void setup(void)
>  {
> -	size_t c_total = 0, nwrite = 0;	/* no. of bytes to be written */
> -
> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> -
> -	TEST_PAUSE;
> +	page_sz = SAFE_SYSCONF(_SC_PAGESIZE);
>  
> -	page_sz = (size_t)getpagesize();
> +	fd = SAFE_OPEN(TEMPFILE, O_RDWR | O_CREAT, 0666);
>  
> -	tst_tmpdir();
> -
> -	if ((fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0)
> -		tst_brkm(TBROK | TERRNO, cleanup, "open failed");
> -
> -	while (c_total < page_sz) {
> -		nwrite = write(fildes, write_buf, sizeof(write_buf));
> -		if (nwrite <= 0)
> -			tst_brkm(TBROK | TERRNO, cleanup, "write failed");
> -		else
> -			c_total += nwrite;
> -	}
> -
> -	/*
> -	 * Call mmap to map virtual memory (mul. of page size bytes) from the
> -	 * beginning of temporary file (offset is 0) into memory.
> -	 */
> -	addr = mmap(0, page_sz, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED,
> -		    fildes, 0);
> -
> -	/* Check for the return value of mmap() */
> -	if (addr == MAP_FAILED)
> -		tst_brkm(TBROK | TERRNO, cleanup, "mmap failed");
> -
> -	/* Set 256 bytes, at 100 byte offset in the mapped region */
> -	memset(addr + 100, 1, 256);
> +	SAFE_LSEEK(fd, page_sz, SEEK_SET);

Why the LSEEK here? If I'm reading the original code correctly it wrote
page_size worth of bytes not a single byte at page size offset.

Also I guess that we have to rewrite the file on each iteration, i.e.

- write page_size bytes 'a'
- mmap() that region and memset() to 'b'
- msync() that region
- read that back by read() and expect it to be changed to 'b'

Also given the speed of current hardware I would make the size of the
msynced() region to be configurable and set the default to a few
megabytes (8 or 16) at least.

> +	SAFE_WRITE(SAFE_WRITE_ALL, fd, "a", 1);
>  }
>  
> -void cleanup(void)
> +static void cleanup(void)
>  {
> -	if (munmap(addr, page_sz) == -1)
> -		tst_resm(TBROK | TERRNO, "munmap failed");
> -
> -	if (close(fildes) == -1)
> -		tst_resm(TWARN | TERRNO, "close failed");
> -
> -	tst_rmdir();
> +	if (fd > 0)
> +		SAFE_CLOSE(fd);
>  }
> +
> +static struct tst_test test = {
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = run,
> +	.needs_tmpdir = 1
> +};
> -- 
> 2.43.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      reply	other threads:[~2024-02-21 14:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19 15:30 [LTP] [PATCH] msync01: Rewrite using new LTP API Avinesh Kumar
2024-02-21 14:04 ` Cyril Hrubis [this message]

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=ZdYDC7m7xJ_MbXR3@yuki \
    --to=chrubis@suse.cz \
    --cc=akumar@suse.de \
    --cc=ltp@lists.linux.it \
    /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