OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [src/] [glue/] [arm/] [smp_test.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
 
2
#include <l4/lib/spinlock.h>
3
#include <l4/lib/printk.h>
4
 
5
#include INC_GLUE(smp.h)
6
#include INC_SUBARCH(cpu.h)
7
 
8
DECLARE_SPINLOCK(smp_lock);
9
 
10
static unsigned long smp_var = 0;
11
static unsigned long signal_finished;
12
 
13
static unsigned long basic_var = 0;
14
 
15
void test_basic_coherent(void)
16
{
17
        dmb();
18
        if (smp_get_cpuid() == 0) {
19
                if (basic_var != 5555) {
20
                        printk("FATAL: variable update not seen. var = %lu\n", basic_var);
21
                        BUG();
22
                }
23
        } else {
24
                basic_var = 5555;
25
                dmb();
26
        }
27
}
28
 
29
void test_smp_coherent(void)
30
{
31
        int other;
32
 
33
        if (smp_get_cpuid() == 1)
34
                other = 0;
35
        else
36
                other = 1;
37
 
38
        /* Increment var */
39
        for (int i = 0; i < 1000; i++) {
40
                spin_lock(&smp_lock);
41
                smp_var++;
42
                spin_unlock(&smp_lock);
43
        }
44
 
45
        /* Signal finished */
46
        spin_lock(&smp_lock);
47
        signal_finished |= (1 << smp_get_cpuid());
48
        spin_unlock(&smp_lock);
49
 
50
        /* Wait for other to finish */
51
        while (!(signal_finished & (1 << other))) {
52
                dmb();
53
        }
54
        if (smp_get_cpuid() == 0) {
55
                printk("Total result: %lu\n", smp_var);
56
                if (smp_var != 2000) {
57
                        printk("FATAL: Total result not as expected\n");
58
                        BUG();
59
                }
60
                printk("%s: Success.\n", __FUNCTION__);
61
        }
62
 
63
}
64
 
65
 
66
static u32 make_mask(int ncpus)
67
{
68
        u32 mask = 0;
69
        while(--ncpus){
70
                mask |= CPUID_TO_MASK(ncpus);
71
        }
72
        mask |= CPUID_TO_MASK(0);
73
 
74
        return mask;
75
}
76
 
77
#ifndef MAX_IPIS
78
#define MAX_IPIS 15
79
#endif
80
 
81
void test_ipi(void)
82
{
83
        int ipi, cpu;
84
        for (ipi = 0; ipi <= MAX_IPIS; ipi++) {
85
                for (cpu = 0; cpu < CONFIG_NCPU; cpu++) {
86
                        if (cpu == smp_get_cpuid())
87
                                continue;
88
                        printk("IPI %d from %d to %d\n", ipi, smp_get_cpuid(), cpu);
89
                        arch_send_ipi(CPUID_TO_MASK(cpu), ipi);
90
                }
91
        }
92
        /* Send IPI to all cores at once */
93
        cpu = make_mask(CONFIG_NCPU);
94
        printk("IPI from %d to all\n", smp_get_cpuid());
95
        arch_send_ipi(cpu, 1);
96
 
97
        printk("IPI from %d to self\n", smp_get_cpuid());
98
        arch_send_ipi(0, 1);             /* Send IPI to self */
99
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.