subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
| 2 | /* */ |
| 3 | /* Copyright (c) International Business Machines Corp., 2007 */ |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 4 | /* Copyright (c) Linux Test Project, 2016 */ |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 5 | /* */ |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 6 | /* This program is free software: you can redistribute it and/or modify */ |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 7 | /* it under the terms of the GNU General Public License as published by */ |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 8 | /* the Free Software Foundation, either version 3 of the License, or */ |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 9 | /* (at your option) any later version. */ |
| 10 | /* */ |
| 11 | /* This program is distributed in the hope that it will be useful, */ |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 12 | /* 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_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 15 | /* */ |
| 16 | /* You should have received a copy of the GNU General Public License */ |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 17 | /* along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 18 | /* */ |
| 19 | /******************************************************************************/ |
| 20 | |
| 21 | /******************************************************************************/ |
| 22 | /* */ |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 23 | /* File: support_numa.c */ |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 24 | /* */ |
| 25 | /* Description: Allocates 1MB of memory and touches it to verify numa */ |
| 26 | /* */ |
| 27 | /* Author: Sivakumar Chinnaiah Sivakumar.C@in.ibm.com */ |
| 28 | /* */ |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 29 | /******************************************************************************/ |
| 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_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 38 | |
| 39 | /* Global Variables */ |
| 40 | #define MB (1<<20) |
| 41 | #define PAGE_SIZE getpagesize() |
| 42 | #define barrier() __asm__ __volatile__("": : :"memory") |
| 43 | |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 44 | static void sigfunc(__attribute__ ((unused)) int sig) |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 45 | { |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 48 | static 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_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 59 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 60 | int main(int argc, char *argv[]) |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 61 | { |
| 62 | int i; |
| 63 | char *buf = NULL; |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 64 | struct sigaction sa; |
| 65 | |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 66 | if (argc != 2) { |
| 67 | fprintf(stderr, "Here expect only one number(i.e. 2) as the parameter.\n"); |
| 68 | exit(1); |
| 69 | } |
| 70 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 71 | switch (atoi(argv[1])) { |
| 72 | case 1: |
| 73 | printf("%d", PAGE_SIZE); |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 74 | return 0; |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 75 | case 2: |
Cyril Hrubis | d218f34 | 2014-09-23 13:14:56 +0200 | [diff] [blame] | 76 | buf = malloc(MB); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 77 | if (!buf) { |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 78 | fprintf(stderr, "Memory is not available\n"); |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 79 | exit(2); |
| 80 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 81 | for (i = 0; i < MB; i += PAGE_SIZE) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 82 | buf[i] = 'a'; |
| 83 | barrier(); |
| 84 | } |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 85 | free(buf); |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 86 | return 0; |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 87 | case 3: |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 88 | /* 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 Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 93 | fprintf(stderr, "Sigaction SIGINT failed\n"); |
| 94 | exit(3); |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 95 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 96 | /* wait for signat Int */ |
| 97 | pause(); |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 98 | return 0; |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 99 | default: |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 100 | help(); |
subrata_modak | 9b555d1 | 2007-08-24 09:41:59 +0000 | [diff] [blame] | 101 | } |
Li Wang | ad38c31 | 2016-12-14 18:08:43 +0800 | [diff] [blame^] | 102 | |
| 103 | return 0; |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 104 | } |