Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7160608

Browse files
committed
tmp save
1 parent 86641db commit 7160608

File tree

10 files changed

+72
-24
lines changed

10 files changed

+72
-24
lines changed

accel/tcg/cpu-exec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,10 @@ int cpu_exec(CPUState *cpu)
733733
//extern void offload_log(FILE*, const char*, ...);
734734
offload_log(stderr, "exec code from %x to %x\n", tb->pc, tb->pc + tb->size);
735735

736-
#if 1
736+
#if 0
737737
// Debug
738738
extern __thread int offload_mode;
739-
if (tb->pc == 0x10128|| tb->pc == 0x127b6)// || (offload_mode == 6 && tb->pc > 0x10000))
739+
if (1||tb->pc == 0x10128|| tb->pc == 0x127b6)// || (offload_mode == 6 && tb->pc > 0x10000))
740740
{
741741
//int32_t tmp[1];
742742
//cpu_memory_rw_debug(cpu, 0x10324, tmp, 4, 1);

linux-user/main.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef struct gst_thrd_info_t{
5454
int server_idx;
5555
int thread_idx;
5656
} gst_thrd_info_t;
57+
int cas_count = 0;
5758

5859
extern __thread int offload_mode; /* 1: server, 2: client 3: exec*/
5960
extern void exec_func(void);
@@ -874,9 +875,11 @@ void offload_server_extra_init(void)
874875
/* To manipulate guest thread's server.
875876
* Short for guest thread place*/
876877
#define GUEST_THREAD_MAX 128
877-
int gst_thrd_plc[GUEST_THREAD_MAX] = {0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
878+
int gst_thrd_plc[GUEST_THREAD_MAX] = {1,1,1,1,2,2,2,2,3,3,3,3,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
878879
//{0};
880+
//{0,1,2,3,4,5,6,7,8,9,10,11};
879881
gst_thrd_info_t gst_thrd_info[GUEST_THREAD_MAX];
882+
int max_server_in_use;
880883

881884
pthread_t center_server_thread;
882885
extern void offload_client_pmd_init(void);
@@ -916,6 +919,7 @@ int main(int argc, char **argv, char **envp)
916919
int server_idx = 0;
917920
for (int i = 0; i < GUEST_THREAD_MAX; i++) {
918921
server_idx = gst_thrd_plc[i];
922+
max_server_in_use = (server_idx > max_server_in_use) ? server_idx : max_server_in_use;
919923
gst_thrd_info[i].server_idx = server_idx;
920924
gst_thrd_info[i].thread_idx = server_thread_count[server_idx]++;
921925
fprintf(stderr, "Thread %d --> [%d->%d]\n",
@@ -1156,6 +1160,10 @@ int main(int argc, char **argv, char **envp)
11561160
thread_env = env;
11571161
if (offload_mode == 2) {
11581162

1163+
if (!parallel_cpus) {
1164+
parallel_cpus = true;
1165+
tb_flush(cpu);
1166+
}
11591167
fprintf(stderr, "offload client mode\n");
11601168

11611169
fprintf(stderr, "size: %x, mask: %x\n", qemu_host_page_size, qemu_host_page_mask);
@@ -1180,8 +1188,8 @@ int main(int argc, char **argv, char **envp)
11801188
pthread_mutex_lock(&offload_center_init_mutex);
11811189
pthread_cond_wait(&offload_center_init_cond, &offload_center_init_mutex);
11821190
pthread_mutex_unlock(&offload_center_init_mutex);
1183-
fprintf(stderr, "Connecting online server\n");
1184-
for (int i = 1; i < 3; i++) {
1191+
fprintf(stderr, "Connecting online server from 1 to %d\n", max_server_in_use -1);
1192+
for (int i = 1; i <= max_server_in_use; i++) {
11851193
extern void offload_connect_online_server(int idx);
11861194
offload_connect_online_server(i);
11871195

linux-user/offload_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,7 @@ void syscall_daemonize(void)
18051805
do_syscall_flag = 0;
18061806
syscall_global_pointer = NULL;
18071807
pthread_mutex_unlock(&do_syscall_mutex);
1808+
syscall_started_flag = 1;
18081809
while (1)
18091810
{
18101811

@@ -2031,7 +2032,6 @@ int offload_client_start(CPUArchState *the_env)
20312032

20322033
void offload_syscall_daemonize_start(CPUArchState *the_env)
20332034
{
2034-
syscall_started_flag = 1;
20352035
offload_mode = 4;
20362036
pthread_mutex_lock(&offload_count_mutex);
20372037
if (is_first_do_syscall_thread == 0)

linux-user/offload_server.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,11 @@ void offload_send_page_request_and_wait(uint32_t page_addr, int perm)
919919
/* send page request; sleep until page is sent back */
920920
int offload_segfault_handler(int host_signum, siginfo_t *pinfo, void *puc)
921921
{
922+
#define PF_TIME
923+
#ifdef PF_TIME
922924
struct timeb t, tend;
923925
ftime(&t);
926+
#endif
924927
siginfo_t *info = pinfo;
925928
ucontext_t *uc = (ucontext_t *)puc;
926929
void* host_addr = info->si_addr;
@@ -929,7 +932,21 @@ int offload_segfault_handler(int host_signum, siginfo_t *pinfo, void *puc)
929932
unsigned long guest_addr = h2g(host_addr);
930933
fprintf(stderr, "[offload_segfault_handler]\tguest addr is %p, host_addr is %lp, pte-0 %p, pte-1 %p, pte-2 %p, VP-2 %p, VP-1%p\n",
931934
guest_addr, host_addr, pt_index(host_addr, 0), pt_index(host_addr, 1), pt_index(host_addr, 2), pt_index(VPTPTR, 2), pt_index(VPTPTR, 1));
935+
#define PC_sig(context) ((context)->uc_mcontext.gregs[REG_RIP])
936+
fprintf(stderr, "[offload_segfault_handler]\tREG_RIP=%p\n",
937+
PC_sig(uc));
938+
#define UC_REG(context, reg) ((context)->uc_mcontext.gregs[reg])
939+
/* REG_10 stores the load/store address.
940+
* which is REG_RBP
941+
* REG_11 stores the load/store value, which is REG_RBX.
942+
*/
943+
//UC_REG(uc, 10) = 0x1000;
944+
//UC_REG(uc, REG_RIP) =
945+
//for (int i = 0; i < __NGREG; i++) {
946+
// fprintf(stderr, "[offload_segfault_handler]\tREG_%d=%p\n",
947+
// i, UC_REG(uc, i));
932948

949+
//}
933950
target_ulong page_addr = guest_addr & TARGET_PAGE_MASK;
934951
//fprintf(stderr, "\nHost instruction address is %p\n", uc->uc_mcontext.gregs[REG_RIP]);
935952
int is_write = ((uc->uc_mcontext.gregs[REG_ERR] & 0x2) != 0);
@@ -941,12 +958,14 @@ int offload_segfault_handler(int host_signum, siginfo_t *pinfo, void *puc)
941958
//get_client_page(is_write, guest_page);
942959
// send page request, sleep until content is sent back.
943960
//fprintf(stderr, "[offload_segfault_handler]\t%p value is %p\n", guest_addr, *(uint32_t*)(g2h(guest_addr)));
961+
#ifdef PF_TIME
944962
ftime(&tend);
945963
int secDiff = tend.time - t.time;
946964
secDiff *= 1000;
947965
secDiff += (tend.millitm - t.millitm);
948966
pgfault_time_sum += secDiff;
949967
fprintf(stderr, "[offload_segfault_handler]\tbegin: %d:%d; end: %d:%d, used: %dms, now total is: %dms", t.time, t.millitm, tend.time, tend.millitm, secDiff, pgfault_time_sum);
968+
#endif
950969

951970
return 1;
952971
}
@@ -1317,6 +1336,7 @@ static void offload_server_send_futex_wait_request(target_ulong guest_addr, int
13171336
//page_recv_flag = 0;
13181337
//offload_server_send_futex_wait_request(guest_addr, op, val, timeout, uaddr2, val3);
13191338
fprintf(stderr, "[offload_server_futex_wait]\t[*(uint32_t*)g2h(guest_addr) %d != val %d, sleeping...]\n", *(uint32_t*)g2h(guest_addr), val);
1339+
exit(222);
13201340
pthread_mutex_lock(&futex_mutex);
13211341
futex_uaddr_changed_flag = 0;
13221342
while (futex_uaddr_changed_flag == 0)
@@ -1402,6 +1422,7 @@ abi_long pass_syscall(void *cpu_env, int num, abi_long arg1,
14021422
struct tcp_msg_header *tcp_header = (struct tcp_msg_header *) buf;
14031423
fill_tcp_header(tcp_header, pp - buf - sizeof(struct tcp_msg_header), TAG_OFFLOAD_SYSCALL_REQ);
14041424

1425+
pthread_mutex_lock(&syscall_recv_mutex[offload_thread_idx]);
14051426
int res = autoSend(client_socket, buf, pp - buf, 0);
14061427
if (res < 0)
14071428
{
@@ -1410,7 +1431,6 @@ abi_long pass_syscall(void *cpu_env, int num, abi_long arg1,
14101431
}
14111432
fprintf(stderr, "[pass_syscall]\tpassed syscall, waiting...%d->%d\n", offload_server_idx, offload_thread_idx);
14121433
syscall_ready_flag[offload_thread_idx] = 0;
1413-
pthread_mutex_lock(&syscall_recv_mutex[offload_thread_idx]);
14141434
while (syscall_ready_flag[offload_thread_idx] == 0)
14151435
{
14161436
pthread_cond_wait(&syscall_recv_cond[offload_thread_idx], &syscall_recv_mutex[offload_thread_idx]);
@@ -1439,7 +1459,7 @@ static void offload_server_process_syscall_result(void)
14391459
int thread_id = (*(int*)p);
14401460
p += sizeof(int);
14411461
result_global[thread_id] = result;
1442-
fprintf(stderr, "[offload_server_process_syscall_result]\tgot syscall ret = %p, waking up thread\n", result);
1462+
fprintf(stderr, "[offload_server_process_syscall_result]\tgot syscall ret = %p, waking up thread%d\n", result, thread_id);
14431463
pthread_mutex_lock(&syscall_recv_mutex[thread_id]);
14441464
syscall_ready_flag[thread_id] = 1;
14451465
pthread_cond_signal(&syscall_recv_cond[thread_id]);

linux-user/syscall.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9064,6 +9064,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
90649064
//rcu_unregister_thread();
90659065
//pthread_exit(NULL);
90669066

9067+
extern int cas_count;
9068+
fprintf(stderr, "end::helper_offload_cmpxchg_prelude\tCAS_COUNT: %d\n", cas_count);
90679069

90689070
extern void cpu_exit_signal(void);
90699071
cpu_exit_signal();
@@ -11185,6 +11187,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
1118511187
/* new thread calls */
1118611188
case TARGET_NR_exit_group:
1118711189
preexit_cleanup(cpu_env, arg1);
11190+
extern int cas_count;
11191+
fprintf(stderr, "end::helper_offload_cmpxchg_prelude\tCAS_COUNT: %d\n", cas_count);
1118811192
ret = get_errno(exit_group(arg1));
1118911193
break;
1119011194
#endif
@@ -13180,6 +13184,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
1318013184
extern int syscall_started_flag;
1318113185
extern __thread int offload_mode;
1318213186
extern int offload_server_idx;
13187+
//while (syscall_started_flag!=1) {
13188+
// sched_yield();
13189+
//}
1318313190
if ((offload_mode == 3) && (offload_server_idx == 0) && (syscall_started_flag == 1))
1318413191
{
1318513192
//TODO

run_server.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
echo "do for 10000 times:\n./arm-linux-user/qemu-arm --offloadmode server --offloadindex $1 ../workload/a.out"
33
for i in `seq 1 10000`;do
4-
time ./arm-linux-user/qemu-arm --strace --offloadmode server --offloadindex $1 ../workload/blackscholes_time;
4+
time taskset $2 ./arm-linux-user/qemu-arm --strace --offloadmode server --offloadindex $1 ../workload/blackscholes_time;
55
echo $i
66
done
77

target/arm/op_helper.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,9 +1454,13 @@ void HELPER(offload_cmpxchg_prelude)(uint32_t addr, uint32_t newv, uint32_t cmpv
14541454
{
14551455
//fprintf(stderr, "helper_offload_cmpxchg_prelude#%d\taddr:%p, cmpv: %x, newv: %x, now val:%x\n", offload_server_idx, addr, cmpv, newv, *(uint32_t *)g2h(addr));
14561456
//if (offload_server_idx != 0)
1457-
// offload_segfault_handler_positive(addr, 2);
1457+
//offload_segfault_handler_positive(addr, 2);
1458+
extern int cas_count;
1459+
cas_count++;
1460+
1461+
fprintf(stderr, "helper_offload_cmpxchg_prelude\tCAS_COUNT: %d\n", cas_count);
14581462
//if (offload_server_idx!=0)
1459-
offload_server_send_cmpxchg_start(addr, cmpv, newv);
1463+
//offload_server_send_cmpxchg_start(addr, cmpv, newv);
14601464
}
14611465

14621466
void HELPER(offload_cmpxchg_epilogue)(uint32_t addr, uint32_t newv, uint32_t cmpv)
@@ -1490,12 +1494,12 @@ int fs_new[5];
14901494

14911495
void HELPER(print_aa32_addr)(uint32_t addr)
14921496
{
1493-
if (!fs_flag) {
1494-
return;
1495-
}
1496-
//extern int offload_server_idx;
1497-
//if (offload_server_idx > 0)
1498-
//fprintf(stderr, "[print_aa32_addr]\taa32 addr = %x\n", addr);
1497+
//if (!fs_flag) {
1498+
// return;
1499+
//}
1500+
extern int offload_server_idx;
1501+
if (offload_server_idx > 0)
1502+
fprintf(stderr, "[print_aa32_addr]\taa32 addr = %x\n", addr);
14991503
}
15001504

15011505
typedef struct PageMapDesc_server {

target/arm/translate.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ static inline void replace_false_sharing_addr(TCGv_i32 addr)
11531153
//tcg_temp_free(offset);
11541154
//tcg_temp_free(base);
11551155
//tcg_gen_print_aa32_addr(addr);
1156-
gen_helper_dqemu_replace_false_sharing_addr(addr, addr);
1156+
//gen_helper_dqemu_replace_false_sharing_addr(addr, addr);
11571157
//tcg_gen_print_aa32_addr(addr);
11581158
}
11591159

@@ -1182,6 +1182,7 @@ static void gen_aa32_ld_i32(DisasContext *s, TCGv_i32 val, TCGv_i32 a32,
11821182

11831183
addr = gen_aa32_addr(s, a32, opc);
11841184
//tcg_gen_print_aa32_addr(addr);
1185+
//tcg_gen_print_aa32_addr(val);
11851186
tcg_gen_qemu_ld_i32(val, addr, index, opc);
11861187
tcg_temp_free(addr);
11871188
}
@@ -1198,6 +1199,7 @@ static void gen_aa32_st_i32(DisasContext *s, TCGv_i32 val, TCGv_i32 a32,
11981199

11991200
addr = gen_aa32_addr(s, a32, opc);
12001201
//tcg_gen_print_aa32_addr(addr);
1202+
//tcg_gen_print_aa32_addr(val);
12011203
tcg_gen_qemu_st_i32(val, addr, index, opc);
12021204
tcg_temp_free(addr);
12031205
}
@@ -8326,8 +8328,8 @@ static void gen_load_exclusive(DisasContext *s, int rt, int rt2,
83268328
TCGv_i32 addr, int size)
83278329
{
83288330

8329-
fprintf(stderr, "gen_load_exclusive, size: %d, addr %p cpu_exclusive_val %p = %p\n", size, addr, &cpu_exclusive_val, cpu_exclusive_val);
8330-
tcg_gen_ldex(addr);
8331+
//fprintf(stderr, "gen_load_exclusive, size: %d, addr %p cpu_exclusive_val %p = %p\n", size, addr, &cpu_exclusive_val, cpu_exclusive_val);
8332+
//tcg_gen_ldex(addr);
83318333
TCGv_i32 tmp = tcg_temp_new_i32();
83328334
TCGMemOp opc = size | MO_ALIGN | s->be_data;
83338335

@@ -8378,7 +8380,7 @@ static void gen_clrex(DisasContext *s)
83788380
static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,
83798381
TCGv_i32 addr, int size)
83808382
{
8381-
fprintf(stderr, "gen_store_exclusive, size: %d, addr %p cpu_exclusive_val %p = %p\n", size, addr, &cpu_exclusive_val, cpu_exclusive_val);
8383+
//fprintf(stderr, "gen_store_exclusive, size: %d, addr %p cpu_exclusive_val %p = %p\n", size, addr, &cpu_exclusive_val, cpu_exclusive_val);
83828384
TCGv_i32 t0, t1, t2;
83838385
TCGv_i64 extaddr;
83848386
TCGv taddr;

tcg/tcg-op.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,7 +2825,7 @@ static void * const table_cmpxchg[16] = {
28252825

28262826
void tcg_gen_ldex(TCGv addr)
28272827
{
2828-
//gen_helper_offload_load_exclusive((uint32_t)addr);
2828+
gen_helper_offload_load_exclusive((uint32_t)addr);
28292829
}
28302830
void tcg_gen_print_aa32_addr(TCGv_i32 addr)
28312831
{
@@ -2838,13 +2838,13 @@ void tcg_gen_atomic_cmpxchg_i32(TCGv_i32 retv, TCGv addr, TCGv_i32 cmpv,
28382838

28392839
// Q1: is TCGv a uint32 ? or a pointer to one.
28402840
// Q2: is content of TCGv plain ?
2841-
fprintf(stderr, "[tcg_gen_atomic_cmpxchg_i32] retv: %d, addr:%p, cmpv: %d, newv: %d, idx: %d, memop: %u\n", retv, (uint32_t)addr, cmpv, newv, idx, memop);
2842-
gen_helper_offload_cmpxchg_prelude((uint32_t) addr, (uint32_t) newv, (uint32_t) cmpv);
28432841
// gen_helper_offload_cpu_exclusive_insight((uint32_t)cpu_exclusive_val, (uint32_t)cpu_exclusive_addr);
28442842

28452843
memop = tcg_canonicalize_memop(memop, 0, 0);
28462844

28472845
if (!(tcg_ctx->tb_cflags & CF_PARALLEL)) {
2846+
fprintf(stderr, "[tcg_gen_atomic_cmpxchg_i32] retv: %d, addr:%p, cmpv: %d, newv: %d, idx: %d, memop: %u\n", retv, (uint32_t)addr, cmpv, newv, idx, memop);
2847+
gen_helper_offload_cmpxchg_prelude((uint32_t) addr, (uint32_t) newv, (uint32_t) cmpv);
28482848
fprintf(stderr, "[tcg_gen_atomic_cmpxchg_i32]\tDEBUG1\n");
28492849
TCGv_i32 t1 = tcg_temp_new_i32();
28502850
TCGv_i32 t2 = tcg_temp_new_i32();

test.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
printf("hellow world!\n");
6+
return 0;
7+
}

0 commit comments

Comments
 (0)