subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
| 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 Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 18 | /* */ |
| 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_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 42 | |
| 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 Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 49 | extern int tst_count; /* to avoid compilation errors. */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 50 | extern char *TESTDIR; /* to avoid compilation errors. */ |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 51 | |
| 52 | /* Global Variables */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 53 | char *TCID = "support_numa"; /* to avoid compilation errors. */ |
| 54 | int TST_TOTAL = 1; /* to avoid compilation errors. */ |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 55 | |
| 56 | void sigfunc(int sig) |
| 57 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 58 | tst_resm(TINFO, "#Caught signal signum=%d", sig); |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 59 | } |
| 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 Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 77 | int main(int argc, char *argv[]) |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 78 | { |
| 79 | int i; |
| 80 | char *buf = NULL; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 81 | int count = 0; |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 82 | struct sigaction sa; |
| 83 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 84 | switch (atoi(argv[1])) { |
| 85 | case 1: |
| 86 | printf("%d", PAGE_SIZE); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 87 | tst_exit(); |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 88 | case 2: |
Cyril Hrubis | d218f34 | 2014-09-23 13:14:56 +0200 | [diff] [blame] | 89 | buf = malloc(MB); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 90 | if (!buf) { |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 91 | tst_resm(TINFO, "#Memory is not available\n"); |
| 92 | tst_exit(); |
| 93 | exit(2); |
| 94 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 95 | for (i = 0; i < MB; i += PAGE_SIZE) { |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 96 | count++; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 97 | buf[i] = 'a'; |
| 98 | barrier(); |
| 99 | } |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 100 | free(buf); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 101 | tst_exit(); |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 102 | case 3: |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 103 | /* 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_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 108 | tst_brkm(TBROK, NULL, "#Sigaction SIGINT failed\n"); |
| 109 | tst_exit(); |
| 110 | exit(1); |
| 111 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 112 | /* wait for signat Int */ |
| 113 | pause(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 114 | tst_exit(); |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 115 | default: |
| 116 | exit(1); |
| 117 | } |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 118 | } |