added huge pages tests
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
# git pull origin main
|
||||
cc -g -Wall -o kmeans-pthread.out -mabi=purecap-benchmark -lpthread kmeans-pthread.c
|
||||
cc -g -Wall -o kmeans-pthread.out -lpthread kmeans-pthread.c
|
||||
# sudo time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend ./kmeans-pthread.out
|
||||
|
||||
@@ -39,8 +39,8 @@
|
||||
|
||||
#include "coz.h"
|
||||
|
||||
#define malloc my_malloc
|
||||
#define free my_free
|
||||
// #define malloc my_malloc
|
||||
// #define free my_free
|
||||
|
||||
#define DEF_NUM_POINTS 150000
|
||||
#define DEF_NUM_MEANS 100
|
||||
@@ -258,7 +258,7 @@ void *calc_means(void *arg)
|
||||
}
|
||||
}
|
||||
}
|
||||
free(sum);
|
||||
// free(sum);
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ int main(int argc, char **argv)
|
||||
// Extra code snippet added
|
||||
// printf("Initial alloc called\n");
|
||||
//INITAlloc();
|
||||
INITREGULARALLOC();
|
||||
// INITREGULARALLOC();
|
||||
// init_malloc();
|
||||
|
||||
int num_procs, curr_point;
|
||||
@@ -280,7 +280,7 @@ int main(int argc, char **argv)
|
||||
thread_arg *arg;
|
||||
int num_per_thread, excess;
|
||||
|
||||
parse_args(argc, argv);
|
||||
parse_args(argc, argv);
|
||||
|
||||
points = (int **)malloc(sizeof(int *) * num_points);
|
||||
for (i=0; i<num_points; i++)
|
||||
@@ -390,16 +390,16 @@ int main(int argc, char **argv)
|
||||
// dprintf("\n\nFinal means:\n");
|
||||
dump_points(means, num_means);
|
||||
|
||||
for (i = 0; i < num_points; i++)
|
||||
free(points[i]);
|
||||
free(points);
|
||||
// for (i = 0; i < num_points; i++)
|
||||
// free(points[i]);
|
||||
// free(points);
|
||||
|
||||
for (i = 0; i < num_means; i++)
|
||||
{
|
||||
free(means[i]);
|
||||
}
|
||||
free(means);
|
||||
free(clusters);
|
||||
// for (i = 0; i < num_means; i++)
|
||||
// {
|
||||
// free(means[i]);
|
||||
// }
|
||||
// free(means);
|
||||
// free(clusters);
|
||||
|
||||
// CLEARALLOC();
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
sh build.sh
|
||||
|
||||
time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-350000.txt ./kmeans-pthread.out -d 40 -c 100 -p 350000 -s 1000 > kmeans-bounds-regular-350000-out.txt
|
||||
time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-300000.txt ./kmeans-pthread.out -d 40 -c 100 -p 300000 -s 1000 > kmeans-bounds-regular-300000-out.txt
|
||||
time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-250000.txt ./kmeans-pthread.out -d 40 -c 100 -p 250000 -s 1000 > kmeans-bounds-regular-250000-out.txt
|
||||
time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-200000.txt ./kmeans-pthread.out -d 40 -c 100 -p 200000 -s 1000 > kmeans-bounds-regular-200000-out.txt
|
||||
time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-150000.txt ./kmeans-pthread.out -d 40 -c 100 -p 150000 -s 1000 > kmeans-bounds-regular-150000-out.txt
|
||||
time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-100000.txt ./kmeans-pthread.out -d 40 -c 100 -p 100000 -s 1000 > kmeans-bounds-regular-100000-out.txt
|
||||
# time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-350000.txt ./kmeans-pthread.out -d 40 -c 100 -p 350000 -s 1000 > kmeans-bounds-regular-350000-out.txt
|
||||
# time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-300000.txt ./kmeans-pthread.out -d 40 -c 100 -p 300000 -s 1000 > kmeans-bounds-regular-300000-out.txt
|
||||
# time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-250000.txt ./kmeans-pthread.out -d 40 -c 100 -p 250000 -s 1000 > kmeans-bounds-regular-250000-out.txt
|
||||
# time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-200000.txt ./kmeans-pthread.out -d 40 -c 100 -p 200000 -s 1000 > kmeans-bounds-regular-200000-out.txt
|
||||
# time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-150000.txt ./kmeans-pthread.out -d 40 -c 100 -p 150000 -s 1000 > kmeans-bounds-regular-150000-out.txt
|
||||
LD_PRELOAD=./libjemalloc.so time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-cheri-new-alloc-100000.txt ./kmeans-pthread.out -d 40 -c 100 -p 100000 -s 1000 > kmeans-bounds-cheri-new-100000-out.txt
|
||||
LD_PRELOAD=./regularjemalloc.so time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-new-alloc-100000.txt ./kmeans-pthread.out -d 40 -c 100 -p 100000 -s 1000 > kmeans-bounds-regular-new-100000-out.txt
|
||||
# time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-10000.txt ./kmeans-pthread.out -d 40 -c 100 -p 10000 -s 1000 > kmeans-bounds-regular-10000-out.txt
|
||||
# time pmcstat -d -w 1 -p l1d_tlb_rd -p l2d_tlb_rd -p l1d_tlb_refill -p cpu_cycles -p dtlb_walk -p stall_backend -p ll_cache_miss_rd -o kmeans-regular-alloc-1000.txt ./kmeans-pthread.out -d 40 -c 100 -p 1000 -s 1000 > kmeans-bounds-regular-1000-out.txt
|
||||
@@ -1,54 +1,114 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/malloc.h>
|
||||
/* Copyright (c) 2007-2009, Stanford University
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Stanford University nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <vm/vm.h> // ✅ Defines vm_size_t, vm_offset_t
|
||||
#include <vm/vm_param.h> // ✅ Extra VM-related macros
|
||||
#include <vm/vm_map.h>
|
||||
#include <vm/vm_extern.h> // ✅ Must be included AFTER <vm/vm.h>
|
||||
#ifndef STDDEFINES_H_
|
||||
#define STDDEFINES_H_
|
||||
|
||||
#define HUGE_PAGE_SIZE (2 * 1024 * 1024) // 2MB Large Page
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static void *hugepage_ptr = NULL;
|
||||
//#define TIMING
|
||||
|
||||
static int load_handler(module_t mod, int event, void *arg) {
|
||||
switch (event) {
|
||||
case MOD_LOAD:
|
||||
printf("Loading Huge Page Kernel Module...\n");
|
||||
/* Debug printf */
|
||||
#define dprintf(...) fprintf(stdout, __VA_ARGS__)
|
||||
|
||||
hugepage_ptr = kmem_alloc_contig(HUGE_PAGE_SIZE, M_WAITOK,
|
||||
0, BUS_SPACE_MAXADDR,
|
||||
HUGE_PAGE_SIZE, 0,
|
||||
VM_MEMATTR_DEFAULT);
|
||||
/* Wrapper to check for errors */
|
||||
#define CHECK_ERROR(a) \
|
||||
if (a) \
|
||||
{ \
|
||||
perror("Error at line\n\t" #a "\nSystem Msg"); \
|
||||
assert ((a) == 0); \
|
||||
}
|
||||
|
||||
if (!hugepage_ptr) {
|
||||
printf("Failed to allocate a huge page!\n");
|
||||
return ENOMEM;
|
||||
}
|
||||
printf("Huge page allocated at %p\n", hugepage_ptr);
|
||||
break;
|
||||
|
||||
case MOD_UNLOAD:
|
||||
if (hugepage_ptr) {
|
||||
kmem_free(hugepage_ptr, HUGE_PAGE_SIZE);
|
||||
printf("Huge page freed.\n");
|
||||
}
|
||||
printf("Unloading module...\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
return 0;
|
||||
static inline void *MALLOC(size_t size)
|
||||
{
|
||||
void * temp = malloc(size);
|
||||
assert(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
static moduledata_t superpage_mod = {
|
||||
"superpage",
|
||||
load_handler,
|
||||
NULL
|
||||
};
|
||||
static inline void *CALLOC(size_t num, size_t size)
|
||||
{
|
||||
void * temp = calloc(num, size);
|
||||
assert(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
DECLARE_MODULE(superpage, superpage_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
|
||||
static inline void *REALLOC(void *ptr, size_t size)
|
||||
{
|
||||
void * temp = realloc(ptr, size);
|
||||
assert(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
static inline char *GETENV(char *envstr)
|
||||
{
|
||||
char *env = getenv(envstr);
|
||||
if (!env) return "0";
|
||||
else return env;
|
||||
}
|
||||
|
||||
#define GET_TIME(start, end, duration) \
|
||||
duration.tv_sec = (end.tv_sec - start.tv_sec); \
|
||||
if (end.tv_nsec >= start.tv_nsec) { \
|
||||
duration.tv_nsec = (end.tv_nsec - start.tv_nsec); \
|
||||
} \
|
||||
else { \
|
||||
duration.tv_nsec = (1000000000L - (start.tv_nsec - end.tv_nsec)); \
|
||||
duration.tv_sec--; \
|
||||
} \
|
||||
if (duration.tv_nsec >= 1000000000L) { \
|
||||
duration.tv_sec++; \
|
||||
duration.tv_nsec -= 1000000000L; \
|
||||
}
|
||||
|
||||
static inline unsigned int time_diff (
|
||||
struct timeval *end, struct timeval *begin)
|
||||
{
|
||||
#ifdef TIMING
|
||||
uint64_t result;
|
||||
|
||||
result = end->tv_sec - begin->tv_sec;
|
||||
result *= 1000000; /* usec */
|
||||
result += end->tv_usec - begin->tv_usec;
|
||||
|
||||
return result;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void get_time (struct timeval *t)
|
||||
{
|
||||
#ifdef TIMING
|
||||
gettimeofday (t, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // STDDEFINES_H_
|
||||
|
||||
Reference in New Issue
Block a user