blob: 3991955f113170fff41cca5b74893691966a10c1 [file] [log] [blame]
subrata_modak9b555d12007-08-24 09:41:59 +00001/******************************************************************************/
2/* */
3/* Copyright (c) International Business Machines Corp., 2007 */
4/* */
5/* This program is free software; you can redistribute it and/or modify */
6/* it under the terms of the GNU General Public License as published by */
7/* the Free Software Foundation; either version 2 of the License, or */
8/* (at your option) any later version. */
9/* */
10/* This program is distributed in the hope that it will be useful, */
11/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
13/* the GNU General Public License for more details. */
14/* */
15/* You should have received a copy of the GNU General Public License */
16/* along with this program; if not, write to the Free Software */
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
subrata_modak9b555d12007-08-24 09:41:59 +000018/* */
19/******************************************************************************/
20
21/******************************************************************************/
22/* */
23/* File: support_numa.c */
24/* */
25/* Description: Allocates 1MB of memory and touches it to verify numa */
26/* */
27/* Author: Sivakumar Chinnaiah Sivakumar.C@in.ibm.com */
28/* */
29/* History: Created - Jul 18 2007 - Sivakumar Chinnaiah */
30/* Sivakumar.C@in.ibm.com */
31/* */
32/******************************************************************************/
33
34#include <stdio.h>
35#include <stdlib.h>
36#include <errno.h>
37#include <unistd.h>
38#include <signal.h>
39#include <limits.h>
40#include <string.h>
41#include "test.h"
subrata_modak9b555d12007-08-24 09:41:59 +000042
43/* Global Variables */
44#define MB (1<<20)
45#define PAGE_SIZE getpagesize()
46#define barrier() __asm__ __volatile__("": : :"memory")
47
48/* Extern Global Variables */
Caspar Zhangd59a6592013-03-07 14:59:12 +080049extern int tst_count; /* to avoid compilation errors. */
Wanlong Gao354ebb42012-12-07 10:10:04 +080050extern char *TESTDIR; /* to avoid compilation errors. */
subrata_modak9b555d12007-08-24 09:41:59 +000051
52/* Global Variables */
Wanlong Gao354ebb42012-12-07 10:10:04 +080053char *TCID = "support_numa"; /* to avoid compilation errors. */
54int TST_TOTAL = 1; /* to avoid compilation errors. */
subrata_modak9b555d12007-08-24 09:41:59 +000055
56void sigfunc(int sig)
57{
Wanlong Gao354ebb42012-12-07 10:10:04 +080058 tst_resm(TINFO, "#Caught signal signum=%d", sig);
subrata_modak9b555d12007-08-24 09:41:59 +000059}
60
61/******************************************************************************/
62/* */
63/* Function: main */
64/* */
65/* Description: Alloctes 1MB of memory and touches it to verify numa behaviour*/
66/* */
67/* Input: Describe input arguments to this program */
68/* argv[1] ==1 then print pagesize */
69/* argv[1] ==2 then allocate 1MB of memory */
70/* argv[1] ==3 then pause the program to catch sigint */
71/* */
72/* Exit: On failure - Exits with non-zero value. */
73/* On success - exits with 0 exit value. */
74/* */
75/******************************************************************************/
76
Wanlong Gao354ebb42012-12-07 10:10:04 +080077int main(int argc, char *argv[])
subrata_modak9b555d12007-08-24 09:41:59 +000078{
79 int i;
80 char *buf = NULL;
Wanlong Gao354ebb42012-12-07 10:10:04 +080081 int count = 0;
subrata_modak9b555d12007-08-24 09:41:59 +000082 struct sigaction sa;
83
Wanlong Gao354ebb42012-12-07 10:10:04 +080084 switch (atoi(argv[1])) {
85 case 1:
86 printf("%d", PAGE_SIZE);
Garrett Cooper2c282152010-12-16 00:55:50 -080087 tst_exit();
subrata_modak9b555d12007-08-24 09:41:59 +000088 case 2:
Cyril Hrubisd218f342014-09-23 13:14:56 +020089 buf = malloc(MB);
Wanlong Gao354ebb42012-12-07 10:10:04 +080090 if (!buf) {
subrata_modak9b555d12007-08-24 09:41:59 +000091 tst_resm(TINFO, "#Memory is not available\n");
92 tst_exit();
93 exit(2);
94 }
Wanlong Gao354ebb42012-12-07 10:10:04 +080095 for (i = 0; i < MB; i += PAGE_SIZE) {
subrata_modak9b555d12007-08-24 09:41:59 +000096 count++;
Wanlong Gao354ebb42012-12-07 10:10:04 +080097 buf[i] = 'a';
98 barrier();
99 }
subrata_modak9b555d12007-08-24 09:41:59 +0000100 free(buf);
Garrett Cooper2c282152010-12-16 00:55:50 -0800101 tst_exit();
subrata_modak9b555d12007-08-24 09:41:59 +0000102 case 3:
Wanlong Gao354ebb42012-12-07 10:10:04 +0800103 /* Trap SIGINT */
104 sa.sa_handler = sigfunc;
105 sa.sa_flags = SA_RESTART;
106 sigemptyset(&sa.sa_mask);
107 if (sigaction(SIGINT, &sa, 0) < 0) {
subrata_modak9b555d12007-08-24 09:41:59 +0000108 tst_brkm(TBROK, NULL, "#Sigaction SIGINT failed\n");
109 tst_exit();
110 exit(1);
111 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800112 /* wait for signat Int */
113 pause();
Garrett Cooper2c282152010-12-16 00:55:50 -0800114 tst_exit();
subrata_modak9b555d12007-08-24 09:41:59 +0000115 default:
116 exit(1);
117 }
Chris Dearmanec6edca2012-10-17 19:54:01 -0700118}