//****************************************************************************** //MI02 MANAGEMENT INFORMATION * // DEVICE ID: 2f129 HID: N/A * // FILENAME: sparemem.c LANGUAGE: C * // LOAD MODUL: sparemem SYSTEM: Utility * // COMPILER: cc UNIT: sparemem * // ITRNR RATE: N/A CPU TYPE: Intel Pentium * // LINK EDITOR: ld MODE: N/A * // * //****************************************************************************** //PU01 PURPOSE - AMENDED * // * // Spare memory test program. * // * //****************************************************************************** //PU02 PURPOSE * // Spare memory test program. * // * // * // The software requirements being implemented by this task are identified * // by STLDD paragraph number 3.6.? * // * //****************************************************************************** //PA02 PROGRAM ATTRIBUTES * // LOGICAL RECORDS: GENERAL COMMENTS: * // C LINES: NON-C LINES: * // EXECUTABLE C STMTS: NON-EXEC C STMTS: * // * //****************************************************************************** //SU01 SUBPROGRAM USAGE * // * //****************************************************************************** //CH02 CHANGE HISTORY * // REV DATE ANALYST EMPLOYER DESCRIPTION * // 0 010199 Jon Clifton ASI Initial release * // * //****************************************************************************** //ML01 MODULE LOGIC * // * //****************************************************************************** //ME01 MODULE EXECUTION CONDITIONS * // * // Standalone test of available spare memory. Requests all memory not * // used by OS and REALTIME tasks. * // * //****************************************************************************** //CI01 LIBRARY AND USER HEADER FILES * // * #include #include #include #include #include #include #include #include #include //****************************************************************************** //CC01 GLOBAL CONSTANTS * // * #define verbose 1 #define PRIORITY 90 #define ONE_MB 0x100000 //****************************************************************************** //CE01 EXTERNALLY DEFINED VARIABLES * // * //****************************************************************************** //CT01 STRUCTURE DEFINITIONS * // * //****************************************************************************** //CG01 GLOBAL SYMBOL DECLARATIONS * // * //****************************************************************************** //CS01 STATIC SYMBOL DECLARATIONS * // * //****************************************************************************** //CP01 MODULE PROTOTYPES * // * //****************************************************************************** //SC01 SOURCE CODE * // * void main() { //****************************************************************************** //LC01 LOCAL SYMBOL DECLARATIONS * // * int i,j, k; // loop counters char* sparemem_p; // pointer to memory allocated int* dirty_p; // pointer to dirty up memory int mb_mem=ONE_MB; // size of memory allocated int pid; // Process ID struct sched_param sched; //****************************************************************************** //EX01 EXECUTABLE STATEMENTS * // * //****************************************************************************** pid = (int) getpid(); if (0 != geteuid()) { printf("ex1exec: MUST BE ROOT TO LOCK MEMORY\n"); exit(1); } /************************************************************** * Change scheduling to FIFO for Real_Time. * * Must be root or setuid root to execute sched_setscheduler. * **************************************************************/ //sched.sched_priority = PRIORITY; //i = sched_setscheduler(0, SCHED_FIFO, &sched); if (i) perror("sched_setscheduler failed"); i = sched_getscheduler(0); if (i<0) perror("sched_getscheduler failed"); else printf("Schedule policy %d, ", i); i = sched_getparam(0, &sched); if (i<0) perror("sched_getparam failed"); else printf("priority %d\n", sched.sched_priority); /********************************************************* * Must be root or setuid root to execute mlockall * *********************************************************/ while (NULL != (sparemem_p=(char*)malloc(ONE_MB))) { printf("Trying to allocate %d MB\n",mb_mem/ONE_MB); i = mlockall(MCL_CURRENT); if (i) { perror("mlockall failed"); break; } // memset(sparemem_p,mb_mem, '!'); srand(pid); dirty_p = (int*)sparemem_p; for (i=0;i<(ONE_MB/sizeof(int));i++) { *dirty_p++ = rand(); } // i = munlockall(); // if (i) { // perror("munlockall failed"); // break; // } // free(sparemem_p); mb_mem+=ONE_MB; }; printf("Available memory = %d MB\n",mb_mem/ONE_MB); for (;;) rand(); return; } /* end of sparemem */