Linux-rt-users archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] rt-tests: Use a distinct shm file for each cyclictest instance
@ 2020-02-07 22:34 John Kacur
  0 siblings, 0 replies; only message in thread
From: John Kacur @ 2020-02-07 22:34 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, John Kacur

When running multiple instances of cyclictest, getting a snapshot from
one will overwrite any snapshots from other instances.

So, create a different shm_file based on the pid for each instance.

For example if you have two instances of cyclictest running
ls /dev/shm/
cyclictest8264  cyclictest8276

You can also use the pid from the file name to know where to send
SIGUSR2

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/cyclictest/cyclictest.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index beac9a3ce946..2f07426389b3 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -235,6 +235,9 @@ static int latency_target_fd = -1;
 static int32_t latency_target_value = 0;
 
 static int rstat_fd = -1;
+/* strlen("/cyclictest") + digits in max pid len + '\0' */
+#define SHM_BUF_SIZE 19
+static char shm_name[SHM_BUF_SIZE];
 
 /* Latency trick
  * if the file /dev/cpu_dma_latency exists,
@@ -1806,9 +1809,15 @@ static void trigger_update(struct thread_param *par, int diff, int64_t ts)
 static int rstat_shm_open(void)
 {
 	int fd;
+	pid_t pid;
+
+	pid = getpid();
+	printf("pid = %d", pid);
+
+	snprintf(shm_name, SHM_BUF_SIZE, "%s%d", "/cyclictest", pid);
 
 	errno = 0;
-	fd = shm_unlink("/cyclictest_shm");
+	fd = shm_unlink(shm_name);
 
 	if ((fd == -1) && (errno != ENOENT)) {
 		fprintf(stderr, "ERROR: shm_unlink %s\n", strerror(errno));
@@ -1816,7 +1825,7 @@ static int rstat_shm_open(void)
 	}
 
 	errno = 9;
-	fd = shm_open("/cyclictest_shm", O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+	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));
 	}
@@ -1894,7 +1903,7 @@ rstat_err2:
 	munmap(mptr, _SC_PAGE_SIZE);
 rstat_err1:
 	close(sfd);
-	shm_unlink("/cyclictest_shm");
+	shm_unlink(shm_name);
 rstat_err:
 	rstat_fd = -1;
 	return;
@@ -2317,7 +2326,7 @@ int main(int argc, char **argv)
 
 	/* Remove running status shared memory file if it exists */
 	if (rstat_fd >= 0)
-		shm_unlink("/cyclictest_shm");
+		shm_unlink(shm_name);
 
 	exit(ret);
 }
-- 
2.20.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-07 22:34 [PATCH] rt-tests: Use a distinct shm file for each cyclictest instance John Kacur

Linux-rt-users archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rt-users/0 linux-rt-users/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rt-users linux-rt-users/ https://lore.kernel.org/linux-rt-users \
		linux-rt-users@vger.kernel.org
	public-inbox-index linux-rt-users

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rt-users


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git