# CCU finalProject
## CURRENT STATUS
Using pthread_spinlock in each thread to secure the critical section.
In the critical section, we perform some floating point arithmetic, and record the time cost by swithes in and the time cost by switches out.
Then we use these time records to calculate the total switching time.
In the beginning, we create threads to test the CPU's core swithcing overhead of communication.
In each thread, it will access the global data to do each core's data communication. And we made it a for-loop to access about 100 times, which will make the amount of time cost larger, so the result would be more easier for us to check.
Then, we record the finish time of accessing the global data, and check how long the time that the thread changing and data accessing costs.
Time checking and data accessing are placed in C.S. which is lock by pthread_spin_lock().
Each thread will repeat 100 times to compute the average time cost.
## ENVIRONMENT
Currently we are running those test on these listed machine
1. Ryzen 3500x
2. Ryzen 4750u
3. i7-4790
```shell=
lstopo -l --ignore pci --ignore block --of png > lstopo.png
```
The lstopo graph on Ryzen 3500x

The lstopo graph on Ryzen 4750u

The lstopo graph on i7-4790

## STEP
1. using [test.sh](https://github.com/GrislyMe/ccu-os-graduate-project/blob/main/test.sh) to run the test
```shell=
./test.sh
```
## Performance Evaluation
### CCX Evaluation
each element of matrix is average of 10k times switches
Perform on Ryzen 4750u

Perform on Ryzen 3500x

Perform on i7-4790

### Performance Comparison

On Ryzen 4750u machine, we are testing lock method's fairness in 100 seconds, the lighter blocks are, the v-core got the CS more frquency, results are very similar to Figure 3 in the paper.

On our platform of 8 core(16 threads), the MCS lock, ticket lock and plock performed within a reasonable range, but the SoA lock didn't perform as our expectation.
We think the problem might be caused by the numbers of core because our core number is not that much, and the CCX, either.
So the switching overhead is not much enough, thus the time to run the algorithm might cost more time than the switching overhead.
## Reference
https://www.cs.rice.edu/~johnmc/comp522/lecture-notes/COMP522-2019-LocksOnMulticore.pdf