-
-
Save gwydirsam/6f25309b720350b6883dc2cd1f398349 to your computer and use it in GitHub Desktop.
A small program to
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* tlbshoot.c - A program used to test SmartOS TLB shoot down. | |
* | |
* This program simply creates a shared memory segment of fixed size | |
* attaches to the shm segment then detaches repeatedly to cause TLB | |
* flushes. | |
*/ | |
#include <sys/types.h> | |
#include <sys/ipc.h> | |
#include <sys/shm.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#define IPCProtection (0600) /* access/modify by user only */ | |
#define SHMGET_FLAGS (IPC_CREAT | IPC_EXCL | IPCProtection) | |
#define SHMAT_FLAGS SHM_SHARE_MMU | |
int main() { | |
int shmid; | |
size_t size = 32000000000; | |
char *shm; | |
/* | |
* Create the segment. | |
*/ | |
if ((shmid = shmget(getpid(), size, SHMGET_FLAGS)) < 0) { | |
perror("shmget"); | |
exit(1); | |
} | |
for (int i = 0;;i++) { | |
printf("Iteration: %d\n", i); | |
/* | |
* Now we attach the segment to our data space. | |
*/ | |
if ((shm = shmat(shmid, NULL, SHMAT_FLAGS)) == (char *) -1) { | |
perror("shmat"); | |
exit(1); | |
} | |
/* | |
* Detach | |
*/ | |
if (shmdt(shm) != 0) { | |
perror("shmdt"); | |
exit(1); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment