public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Lukas Beckmann <lbckmnn@mailbox.org>
To: John Kacur <jkacur@redhat.com>
Cc: rt-users <linux-rt-users@vger.kernel.org>,
	Lukas Beckmann <lbckmnn@mailbox.org>
Subject: [PATCH 2/2] cyclictest: simplify rstat_setup
Date: Sun,  1 Mar 2026 22:24:07 +0100	[thread overview]
Message-ID: <20260301212407.3146506-3-lbckmnn@mailbox.org> (raw)
In-Reply-To: <20260301212407.3146506-1-lbckmnn@mailbox.org>

The shm file is truncated to zero each time before it is written.
It does not make sense to truncate it to something non zero on setup or
to mlock it.

Signed-off-by: Lukas Beckmann <lbckmnn@mailbox.org>
---
 src/cyclictest/cyclictest.c | 89 ++++++-------------------------------
 1 file changed, 13 insertions(+), 76 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 960c905..7b959ac 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -1771,33 +1771,6 @@ static void trigger_update(struct thread_param *par, int diff, int64_t ts)
 	pthread_mutex_unlock(&trigger_lock);
 }
 
-/* Running status shared memory open */
-static int rstat_shm_open(void)
-{
-	int fd;
-	pid_t pid;
-
-	pid = getpid();
-
-	snprintf(shm_name, SHM_BUF_SIZE, "%s%d", "/cyclictest", pid);
-
-	errno = 0;
-	fd = shm_unlink(shm_name);
-
-	if ((fd == -1) && (errno != ENOENT)) {
-		fprintf(stderr, "ERROR: shm_unlink %s\n", strerror(errno));
-		return fd;
-	}
-
-	errno = 9;
-	fd = shm_open(shm_name, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
-	if (fd == -1)
-		fprintf(stderr, "ERROR: shm_open %s\n", strerror(errno));
-
-	rstat_fd = fd;
-
-	return fd;
-}
 
 static int rstat_ftruncate(int fd, off_t len)
 {
@@ -1811,62 +1784,26 @@ static int rstat_ftruncate(int fd, off_t len)
 	return err;
 }
 
-static void *rstat_mmap(int fd)
-{
-	void *mptr;
 
-	errno = 0;
-	mptr = mmap(0, _SC_PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+static void rstat_setup(void)
+{
+	int fd;
+	pid_t pid;
 
-	if (mptr == (void*)-1)
-		fprintf(stderr, "ERROR: mmap, %s\n", strerror(errno));
+	pid = getpid();
 
-	return mptr;
-}
+	snprintf(shm_name, SHM_BUF_SIZE, "%s%d", "/cyclictest", pid);
 
-static int rstat_mlock(void *mptr)
-{
-	int err;
+	fd = shm_unlink(shm_name);
 
-	errno = 0;
-	err = mlock(mptr, _SC_PAGE_SIZE);
-	if (err == -1)
-		fprintf(stderr, "ERROR, mlock %s\n", strerror(errno));
+	if ((fd == -1) && (errno != ENOENT))
+		fprintf(stderr, "ERROR: shm_unlink %s\n", strerror(errno));
 
-	return err;
-}
+	fd = shm_open(shm_name, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+	if (fd == -1)
+		fprintf(stderr, "ERROR: shm_open %s\n", strerror(errno));
 
-static void rstat_setup(void)
-{
-	int res;
-	void *mptr = NULL;
-
-	int sfd = rstat_shm_open();
-	if (sfd < 0)
-		goto rstat_err;
-
-	res = rstat_ftruncate(sfd, _SC_PAGE_SIZE);
-	if (res)
-		goto rstat_err1;
-
-	mptr = rstat_mmap(sfd);
-	if (mptr == MAP_FAILED)
-		goto rstat_err1;
-
-	res = rstat_mlock(mptr);
-	if (res)
-		goto rstat_err2;
-
-	return;
-
-rstat_err2:
-	munmap(mptr, _SC_PAGE_SIZE);
-rstat_err1:
-	close(sfd);
-	shm_unlink(shm_name);
-rstat_err:
-	rstat_fd = -1;
-	return;
+	rstat_fd = fd;
 }
 
 static void write_stats(FILE *f, void *data)
-- 
2.53.0


  parent reply	other threads:[~2026-03-01 21:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-01 21:24 [PATCH 0/2] cyclictest: fix growing shm stat file Lukas Beckmann
2026-03-01 21:24 ` [PATCH 1/2] " Lukas Beckmann
2026-03-09 22:54   ` John Kacur
2026-03-01 21:24 ` Lukas Beckmann [this message]
2026-03-09 22:55   ` [PATCH 2/2] cyclictest: simplify rstat_setup John Kacur
2026-03-10 13:30     ` Crystal Wood
2026-03-10 16:18       ` John Kacur
2026-03-10 16:57         ` Crystal Wood

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=20260301212407.3146506-3-lbckmnn@mailbox.org \
    --to=lbckmnn@mailbox.org \
    --cc=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    /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