on master help sign in
Merge pull request #241 from fmap/master

A few RTS fixes.

commit17fb34a6f89b1abe1788d13e06a8359b98f270c1 authorEdwin Brady <edwin.brady@gmail.com> dateMon 18 Mar 2013, 15:42 (14 years ago) parente8d3f09acf39f8
4 files changed+23−30
rts/idris_gc.c+1−3 rts/idris_rts.c+2−18 rts/idris_rts.h+1−5 rts/idris_stats.c+19−4
rts/idris_gc.c+1−3
@@ -101,9 +101,7 @@ void idris_gc(VM* vm) {
101101 for(root = vm->inbox_ptr; root < vm->inbox_write; ++root) {
102102 *root = copy(vm, *root);
103103 }
104− for(root = vm->argv; root < vm->argv + vm->argc; ++root) {
105− *root = copy(vm, *root);
106− }
104+
107105 vm->ret = copy(vm, vm->ret);
108106 vm->reg1 = copy(vm, vm->reg1);
109107
rts/idris_rts.c+2−18
@@ -20,16 +20,10 @@ VM* init_vm(int stack_size, size_t heap_size,
2020 STATS_ENTER_INIT(vm->stats)
2121
2222 VAL* valstack = malloc(stack_size * sizeof(VAL));
23− int* intstack = malloc(stack_size * sizeof(int));
24− double* floatstack = malloc(stack_size*sizeof(double));
2523
2624 vm->valstack = valstack;
2725 vm->valstack_top = valstack;
2826 vm->valstack_base = valstack;
29− vm->intstack = intstack;
30− vm->intstack_ptr = intstack;
31− vm->floatstack = floatstack;
32− vm->floatstack_ptr = floatstack;
3327 vm->stack_max = valstack + stack_size;
3428
3529 alloc_heap(&(vm->heap), heap_size);
@@ -51,15 +45,9 @@ VM* init_vm(int stack_size, size_t heap_size,
5145 vm->max_threads = max_threads;
5246 vm->processes = 0;
5347
54− int i;
55− // Assumption: there's enough space for this in the initial heap.
56− vm->argv = malloc(argc*sizeof(VAL));
48+ vm->argv = argv;
5749 vm->argc = argc;
5850
59− for(i = 0; i < argc; ++i) {
60− vm->argv[i] = MKSTR(vm, argv[i]);
61− }
62−
6351 STATS_LEAVE_INIT(vm->stats)
6452 return vm;
6553}
@@ -70,10 +58,7 @@ Stats terminate(VM* vm) {
7058
7159 free(vm->inbox);
7260 free(vm->valstack);
73− free(vm->intstack);
74− free(vm->floatstack);
7561 free_heap(&(vm->heap));
76− free(vm->argv);
7762
7863 pthread_mutex_destroy(&(vm -> inbox_lock));
7964 pthread_mutex_destroy(&(vm -> inbox_block));
@@ -592,11 +577,10 @@ int idris_numArgs(VM* vm) {
592577}
593578
594579VAL idris_getArg(VM* vm, int i) {
595− return vm->argv[i];
580+ return MKSTR(vm, vm->argv[i]);
596581}
597582
598583void stackOverflow() {
599584 fprintf(stderr, "Stack overflow");
600585 exit(-1);
601586}
602−
rts/idris_rts.h+1−5
@@ -44,12 +44,8 @@ typedef struct Closure {
4444
4545typedef struct {
4646 VAL* valstack;
47− int* intstack;
48− double* floatstack;
4947 VAL* valstack_top;
5048 VAL* valstack_base;
51− int* intstack_ptr;
52− double* floatstack_ptr;
5349 VAL* stack_max;
5450
5551 Heap heap;
@@ -71,7 +67,7 @@ typedef struct {
7167 Stats stats;
7268
7369 int argc;
74− VAL* argv; // command line arguments
70+ char** argv; // command line arguments
7571
7672 VAL ret;
7773 VAL reg1;
rts/idris_stats.c+19−4
@@ -9,8 +9,23 @@ void print_stats(const Stats * stats) {
99 clock_t total = clock() - stats->start_time;
1010 clock_t mut = total - stats->init_time - stats->gc_time - stats->exit_time;
1111 double mut_sec = (double)mut / CLOCKS_PER_SEC;
12− int avg_chunk = (int)((double)stats->allocations / (double)stats->alloc_count);
13− int alloc_rate = (int)((double)(stats->allocations) / mut_sec);
12+
13+ int avg_chunk = 0;
14+ if (stats->alloc_count > 0) {
15+ avg_chunk = (int)((double)stats->allocations / (double)stats->alloc_count);
16+ }
17+
18+ int alloc_rate = 0;
19+ if (mut > 0) {
20+ alloc_rate = (int)((double)(stats->allocations) / mut_sec);
21+ }
22+
23+ double gc_percent = 0.0d;
24+ double productivity = 0.0d;
25+ if (total > 0) {
26+ gc_percent = 100 * (double)stats->gc_time / (double)total;
27+ productivity = 100 * ((double)mut / (double)total);
28+ }
1429
1530 setlocale(LC_NUMERIC, "");
1631 printf("\n");
@@ -28,11 +43,11 @@ void print_stats(const Stats * stats) {
2843 printf("EXIT time: %8.3fs\n", (double)stats->exit_time / CLOCKS_PER_SEC);
2944 printf("TOTAL time: %8.3fs\n\n", (double)total / CLOCKS_PER_SEC);
3045
31− printf("%%GC time: %.2f%%\n\n", 100 * (double)stats->gc_time / (double)total);
46+ printf("%%GC time: %.2f%%\n\n", gc_percent);
3247
3348 printf("Alloc rate %'d bytes per MUT sec\n\n", alloc_rate);
3449
35− printf("Productivity %.2f%%\n", 100 * ((double)mut / (double)total));
50+ printf("Productivity %.2f%%\n", productivity);
3651}
3752
3853void aggregate_stats(Stats * stats1, const Stats * stats2) {