aboutsummaryrefslogtreecommitdiffstats
path: root/litmus/cache_proc.c
diff options
context:
space:
mode:
Diffstat (limited to 'litmus/cache_proc.c')
-rw-r--r--litmus/cache_proc.c140
1 files changed, 140 insertions, 0 deletions
diff --git a/litmus/cache_proc.c b/litmus/cache_proc.c
index 01350294afaf..397214f2b8cc 100644
--- a/litmus/cache_proc.c
+++ b/litmus/cache_proc.c
@@ -1,3 +1,5 @@
1#include <asm/uaccess.h>
2#include <linux/uaccess.h>
1#include <linux/init.h> 3#include <linux/init.h>
2#include <linux/types.h> 4#include <linux/types.h>
3#include <linux/kernel.h> 5#include <linux/kernel.h>
@@ -7,6 +9,7 @@
7#include <linux/io.h> 9#include <linux/io.h>
8#include <linux/mutex.h> 10#include <linux/mutex.h>
9#include <linux/time.h> 11#include <linux/time.h>
12#include <linux/random.h>
10 13
11#include <litmus/litmus_proc.h> 14#include <litmus/litmus_proc.h>
12#include <litmus/sched_trace.h> 15#include <litmus/sched_trace.h>
@@ -21,6 +24,14 @@
21#define LOCK_ALL (~UNLOCK_ALL) 24#define LOCK_ALL (~UNLOCK_ALL)
22#define MAX_NR_WAYS 16 25#define MAX_NR_WAYS 16
23#define MAX_NR_COLORS 16 26#define MAX_NR_COLORS 16
27#define CACHELINE_SIZE 32
28#define INTS_IN_CACHELINE (CACHELINE_SIZE/sizeof(int))
29#define CACHELINES_IN_1KB (1024 / sizeof(cacheline_t))
30
31typedef struct cacheline
32{
33 int line[INTS_IN_CACHELINE];
34} __attribute__((aligned(CACHELINE_SIZE))) cacheline_t;
24 35
25void mem_lock(u32 lock_val, int cpu); 36void mem_lock(u32 lock_val, int cpu);
26 37
@@ -1121,6 +1132,135 @@ void flush_cache(int all)
1121 raw_spin_unlock_irqrestore(&cache_lock, flags); 1132 raw_spin_unlock_irqrestore(&cache_lock, flags);
1122} 1133}
1123 1134
1135/* src = shared, dst = local */
1136#if 0 // random
1137asmlinkage long sys_run_test(int type, int size, cacheline_t *src, cacheline_t *dst, lt_t __user *ts)
1138{
1139 /* size is in KB */
1140 long ret = 0;
1141 lt_t t1, t2;
1142 int numlines = size * CACHELINES_IN_1KB;
1143 int next, sum = 0, ran;
1144 unsigned long flags;
1145
1146 get_random_bytes(&ran, sizeof(int));
1147 next = ran % ((size*1024)/sizeof(cacheline_t));
1148
1149 //preempt_disable();
1150 if (type == 1) {
1151 int i, j;
1152 color_read_in_mem_lock(0x0000FFF0, 0x0000000f, (void*)src, (void*)src + size*1024);
1153 color_read_in_mem_lock(0x0000FF0F, 0x0000000f, (void*)dst, (void*)dst + size*1024);
1154
1155 local_irq_save(flags);
1156 t1 = litmus_clock();
1157 for (i = 0; i < numlines; i++) {
1158 next = src[next].line[0];
1159 for (j = 1; j < INTS_IN_CACHELINE; j++) {
1160 dst[next].line[j] = src[next].line[j]; // read
1161 //src[next].line[j] = dst[next].line[j]; // write
1162 }
1163 }
1164 t2 = litmus_clock();
1165 local_irq_restore(flags);
1166 sum = next + (int)t2;
1167 t2 -= t1;
1168 ret = put_user(t2, ts);
1169 }
1170 else {
1171 int i, j;
1172 color_read_in_mem_lock(0x0000FF0F, 0x0000000f, (void*)dst, (void*)dst + size*1024);
1173 local_irq_save(flags);
1174 t1 = litmus_clock();
1175 for (i = 0; i < numlines; i++) {
1176 next = src[next].line[0];
1177 for (j = 1; j < INTS_IN_CACHELINE; j++) {
1178 dst[next].line[j] = src[next].line[j]; //read
1179 //src[next].line[j] = dst[next].line[j]; //write
1180 }
1181 }
1182 t2 = litmus_clock();
1183 local_irq_restore(flags);
1184 sum = next + (int)t2;
1185 t2 -= t1;
1186 ret = put_user(t2, ts);
1187 v7_flush_kern_dcache_area(src, size*1024);
1188 }
1189 //preempt_enable();
1190 flush_cache(1);
1191
1192 return ret;
1193}
1194#else
1195// sequential
1196asmlinkage long sys_run_test(int type, int size, cacheline_t *src, cacheline_t *dst, lt_t __user *ts)
1197{
1198 /* size is in KB */
1199 long ret = 0;
1200 lt_t t1, t2;
1201 int numlines = size * CACHELINES_IN_1KB;
1202 int sum = 0;
1203 unsigned long flags;
1204
1205 //preempt_disable();
1206 if (type == 1) {
1207 int i, j;
1208 color_read_in_mem_lock(0x0000FFF0, 0x0000000f, (void*)src, (void*)src + size*1024);
1209 color_read_in_mem_lock(0x0000FF0F, 0x0000000f, (void*)dst, (void*)dst + size*1024);
1210
1211 local_irq_save(flags);
1212 t1 = litmus_clock();
1213 for (i = 0; i < numlines; i++) {
1214 for (j = 0; j < INTS_IN_CACHELINE; j++) {
1215 //dst[i].line[j] = src[i].line[j]; // read
1216 src[i].line[j] = dst[i].line[j]; // write
1217 }
1218 }
1219 t2 = litmus_clock();
1220 local_irq_restore(flags);
1221 sum = (int)(t1 + t2);
1222 t2 -= t1;
1223 ret = put_user(t2, ts);
1224 }
1225 else {
1226 int i, j;
1227 color_read_in_mem_lock(0x0000FF0F, 0x0000000f, (void*)dst, (void*)dst + size*1024);
1228 local_irq_save(flags);
1229 t1 = litmus_clock();
1230 for (i = 0; i < numlines; i++) {
1231 for (j = 0; j < INTS_IN_CACHELINE; j++) {
1232 //dst[i].line[j] = src[i].line[j]; //read
1233 src[i].line[j] = dst[i].line[j]; //write
1234 }
1235 }
1236 t2 = litmus_clock();
1237 local_irq_restore(flags);
1238 sum = (int)(t1 + t2);
1239 t2 -= t1;
1240 ret = put_user(t2, ts);
1241 v7_flush_kern_dcache_area(src, size*1024);
1242 }
1243 //preempt_enable();
1244 flush_cache(1);
1245
1246 return ret;
1247}
1248#endif
1249
1250asmlinkage long sys_lock_buffer(void* vaddr, size_t size, u32 lock_way, u32 unlock_way)
1251{
1252 /* size is in bytes */
1253 long ret = 0;
1254 int i;
1255 u32 lock_val, unlock_val;
1256
1257 lock_val = ~lock_way & 0x0000ffff;
1258 unlock_val = ~unlock_way & 0x0000ffff;
1259 color_read_in_mem_lock(lock_val, unlock_val, (void*)vaddr, (void*)vaddr + size);
1260
1261 return ret;
1262}
1263
1124#define TRIALS 1000 1264#define TRIALS 1000
1125 1265
1126static int perf_test(void) { 1266static int perf_test(void) {