blob: 76140bcd222c9092bd328729b9eb96206680e3c9 [file] [log] [blame]
subrata_modak9b555d12007-08-24 09:41:59 +00001/******************************************************************************/
2/* */
3/* Copyright (c) International Business Machines Corp., 2007 */
Li Wangad38c312016-12-14 18:08:43 +08004/* Copyright (c) Linux Test Project, 2016 */
subrata_modak9b555d12007-08-24 09:41:59 +00005/* */
Li Wangad38c312016-12-14 18:08:43 +08006/* This program is free software: you can redistribute it and/or modify */
subrata_modak9b555d12007-08-24 09:41:59 +00007/* it under the terms of the GNU General Public License as published by */
Li Wangad38c312016-12-14 18:08:43 +08008/* the Free Software Foundation, either version 3 of the License, or */
subrata_modak9b555d12007-08-24 09:41:59 +00009/* (at your option) any later version. */
10/* */
11/* This program is distributed in the hope that it will be useful, */
Li Wangad38c312016-12-14 18:08:43 +080012/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14/* GNU General Public License for more details. */
subrata_modak9b555d12007-08-24 09:41:59 +000015/* */
16/* You should have received a copy of the GNU General Public License */
Li Wangad38c312016-12-14 18:08:43 +080017/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
subrata_modak9b555d12007-08-24 09:41:59 +000018/* */
19/******************************************************************************/
20
21/******************************************************************************/
22/* */
Li Wangad38c312016-12-14 18:08:43 +080023/* File: support_numa.c */
subrata_modak9b555d12007-08-24 09:41:59 +000024/* */
25/* Description: Allocates 1MB of memory and touches it to verify numa */
26/* */
27/* Author: Sivakumar Chinnaiah Sivakumar.C@in.ibm.com */
28/* */
subrata_modak9b555d12007-08-24 09:41:59 +000029/******************************************************************************/
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <errno.h>
34#include <unistd.h>
35#include <signal.h>
36#include <limits.h>
37#include <string.h>
subrata_modak9b555d12007-08-24 09:41:59 +000038
39/* Global Variables */
40#define MB (1<<20)
41#define PAGE_SIZE getpagesize()
42#define barrier() __asm__ __volatile__("": : :"memory")
43
Li Wangad38c312016-12-14 18:08:43 +080044static void sigfunc(__attribute__ ((unused)) int sig)
subrata_modak9b555d12007-08-24 09:41:59 +000045{
subrata_modak9b555d12007-08-24 09:41:59 +000046}
47
Li Wangad38c312016-12-14 18:08:43 +080048static void help(void)
49{
50 printf("Input: Describe input arguments to this program\n");
51 printf(" argv[1] == 1 then print pagesize\n");
52 printf(" argv[1] == 2 then allocate 1MB of memory\n");
53 printf(" argv[1] == 3 then pause the program to catch sigint\n");
54 printf("Exit: On failure - Exits with non-zero value\n");
55 printf(" On success - exits with 0 exit value\n");
56
57 exit(1);
58}
subrata_modak9b555d12007-08-24 09:41:59 +000059
Wanlong Gao354ebb42012-12-07 10:10:04 +080060int main(int argc, char *argv[])
subrata_modak9b555d12007-08-24 09:41:59 +000061{
62 int i;
63 char *buf = NULL;
subrata_modak9b555d12007-08-24 09:41:59 +000064 struct sigaction sa;
65
Li Wangad38c312016-12-14 18:08:43 +080066 if (argc != 2) {
67 fprintf(stderr, "Here expect only one number(i.e. 2) as the parameter.\n");
68 exit(1);
69 }
70
Wanlong Gao354ebb42012-12-07 10:10:04 +080071 switch (atoi(argv[1])) {
72 case 1:
73 printf("%d", PAGE_SIZE);
Li Wangad38c312016-12-14 18:08:43 +080074 return 0;
subrata_modak9b555d12007-08-24 09:41:59 +000075 case 2:
Cyril Hrubisd218f342014-09-23 13:14:56 +020076 buf = malloc(MB);
Wanlong Gao354ebb42012-12-07 10:10:04 +080077 if (!buf) {
Li Wangad38c312016-12-14 18:08:43 +080078 fprintf(stderr, "Memory is not available\n");
subrata_modak9b555d12007-08-24 09:41:59 +000079 exit(2);
80 }
Wanlong Gao354ebb42012-12-07 10:10:04 +080081 for (i = 0; i < MB; i += PAGE_SIZE) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080082 buf[i] = 'a';
83 barrier();
84 }
subrata_modak9b555d12007-08-24 09:41:59 +000085 free(buf);
Li Wangad38c312016-12-14 18:08:43 +080086 return 0;
subrata_modak9b555d12007-08-24 09:41:59 +000087 case 3:
Wanlong Gao354ebb42012-12-07 10:10:04 +080088 /* Trap SIGINT */
89 sa.sa_handler = sigfunc;
90 sa.sa_flags = SA_RESTART;
91 sigemptyset(&sa.sa_mask);
92 if (sigaction(SIGINT, &sa, 0) < 0) {
Li Wangad38c312016-12-14 18:08:43 +080093 fprintf(stderr, "Sigaction SIGINT failed\n");
94 exit(3);
subrata_modak9b555d12007-08-24 09:41:59 +000095 }
Wanlong Gao354ebb42012-12-07 10:10:04 +080096 /* wait for signat Int */
97 pause();
Li Wangad38c312016-12-14 18:08:43 +080098 return 0;
subrata_modak9b555d12007-08-24 09:41:59 +000099 default:
Li Wangad38c312016-12-14 18:08:43 +0800100 help();
subrata_modak9b555d12007-08-24 09:41:59 +0000101 }
Li Wangad38c312016-12-14 18:08:43 +0800102
103 return 0;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700104}