1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * memtoy.h -- local header template for memory toy/tool 3f08c3bdfSopenharmony_ci */ 4f08c3bdfSopenharmony_ci/* 5f08c3bdfSopenharmony_ci * Copyright (c) 2005 Hewlett-Packard, Inc 6f08c3bdfSopenharmony_ci * All rights reserved. 7f08c3bdfSopenharmony_ci */ 8f08c3bdfSopenharmony_ci 9f08c3bdfSopenharmony_ci/* 10f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify 11f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by 12f08c3bdfSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 13f08c3bdfSopenharmony_ci * (at your option) any later version. 14f08c3bdfSopenharmony_ci * 15f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful, 16f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 17f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18f08c3bdfSopenharmony_ci * GNU General Public License for more details. 19f08c3bdfSopenharmony_ci * 20f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License 21f08c3bdfSopenharmony_ci * along with this program; if not, write to the Free Software 22f08c3bdfSopenharmony_ci * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23f08c3bdfSopenharmony_ci */ 24f08c3bdfSopenharmony_ci#ifndef _MEMTOY_H 25f08c3bdfSopenharmony_ci#define _MEMTOY_H 26f08c3bdfSopenharmony_ci#include <sys/types.h> 27f08c3bdfSopenharmony_ci#include <sys/time.h> 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_ci#include <setjmp.h> 30f08c3bdfSopenharmony_ci#include <signal.h> 31f08c3bdfSopenharmony_ci 32f08c3bdfSopenharmony_ci#include "segment.h" 33f08c3bdfSopenharmony_ci#include "version.h" 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_ci#define BOGUS_SIZE ((size_t)-1) 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_citypedef enum {false=0, true} bool; 38f08c3bdfSopenharmony_ci 39f08c3bdfSopenharmony_ci/* 40f08c3bdfSopenharmony_ci * program global data 41f08c3bdfSopenharmony_ci */ 42f08c3bdfSopenharmony_citypedef struct global_context { 43f08c3bdfSopenharmony_ci char *program_name; /* argv[0] - for reference in messages */ 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_ci unsigned long options; /* command line options, ... */ 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_ci siginfo_t *siginfo; /* signal info, if signalled != 0 */ 48f08c3bdfSopenharmony_ci char *signame; /* name of signal, if any */ 49f08c3bdfSopenharmony_ci sigjmp_buf sigjmp_env; /* embedded setjmp buffer */ 50f08c3bdfSopenharmony_ci bool sigjmp; /* sigsetjmp is "armed" */ 51f08c3bdfSopenharmony_ci 52f08c3bdfSopenharmony_ci size_t pagesize; /* system page size for mmap, ... */ 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_ci int numa_max_node; /* if >0, numa supported */ 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_ci segment_t **seglist; /* list of known segments */ 57f08c3bdfSopenharmony_ci segment_t *seg_avail; /* an available segment */ 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_ci char *cmd_name; /* currently executing command */ 60f08c3bdfSopenharmony_ci 61f08c3bdfSopenharmony_ci#ifdef _DEBUG 62f08c3bdfSopenharmony_ci unsigned long debug; /* debug enablement flags */ 63f08c3bdfSopenharmony_ci#endif 64f08c3bdfSopenharmony_ci} glctx_t; 65f08c3bdfSopenharmony_ci 66f08c3bdfSopenharmony_ciextern glctx_t glctx; 67f08c3bdfSopenharmony_ci 68f08c3bdfSopenharmony_ci#define OPTION_VERBOSE 0x0001 69f08c3bdfSopenharmony_ci#define OPTION_INTERACTIVE 0x0100 70f08c3bdfSopenharmony_ci 71f08c3bdfSopenharmony_ci/* 72f08c3bdfSopenharmony_ci * Danger, Will Robinson!! -- hardcoded variable 'gcp' 73f08c3bdfSopenharmony_ci */ 74f08c3bdfSopenharmony_ci#define set_option(OPT) gcp->options |= (OPTION_##OPT) 75f08c3bdfSopenharmony_ci#define clear_option(OPT) gcp->options &= ~(OPION_##OPTT) 76f08c3bdfSopenharmony_ci#define is_option(OPT) ((gcp->options & OPTION_##OPT) != 0) 77f08c3bdfSopenharmony_ci 78f08c3bdfSopenharmony_ci#define show_option(opt, off, on) ( !is_option(opt) ? #off : #on ) 79f08c3bdfSopenharmony_ci 80f08c3bdfSopenharmony_ci#define signalled(GCP) (GCP->siginfo != NULL) 81f08c3bdfSopenharmony_ci 82f08c3bdfSopenharmony_ci/* 83f08c3bdfSopenharmony_ci * different between start and end time in microseconds 84f08c3bdfSopenharmony_ci */ 85f08c3bdfSopenharmony_cistatic unsigned long tv_diff_usec(struct timeval *stp, struct timeval *etp) 86f08c3bdfSopenharmony_ci{ 87f08c3bdfSopenharmony_ci return ((1000000L * (etp)->tv_sec + (etp)->tv_usec) - 88f08c3bdfSopenharmony_ci (1000000L * (stp)->tv_sec + (stp)->tv_usec)); 89f08c3bdfSopenharmony_ci} 90f08c3bdfSopenharmony_ci 91f08c3bdfSopenharmony_ci 92f08c3bdfSopenharmony_ci/* 93f08c3bdfSopenharmony_ci * memtoy.c 94f08c3bdfSopenharmony_ci */ 95f08c3bdfSopenharmony_ciextern void die(int, char*, ... ); 96f08c3bdfSopenharmony_ciextern void vprint(char*, ...); 97f08c3bdfSopenharmony_ciextern void reset_signal(void); 98f08c3bdfSopenharmony_ciextern void wait_for_signal(const char*); 99f08c3bdfSopenharmony_ci 100f08c3bdfSopenharmony_ci/* 101f08c3bdfSopenharmony_ci * commands.c 102f08c3bdfSopenharmony_ci */ 103f08c3bdfSopenharmony_ciextern void process_commands(void); 104f08c3bdfSopenharmony_ciextern void wait_for_signal(const char *); 105f08c3bdfSopenharmony_ciextern void touch_memory(bool, unsigned long*, size_t); 106f08c3bdfSopenharmony_ci 107f08c3bdfSopenharmony_ci#endif 108