Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
Add 'scheduler-test/' from commit 'a76501bedff517b234f45d3a7d5555acf5…
Browse files Browse the repository at this point in the history
…2ee260'

git-subtree-dir: scheduler-test
git-subtree-mainline: d2f61b5
git-subtree-split: a76501b
  • Loading branch information
Codejune committed Nov 24, 2021
2 parents d2f61b5 + a76501b commit 850114f
Show file tree
Hide file tree
Showing 6 changed files with 515 additions and 0 deletions.
61 changes: 61 additions & 0 deletions scheduler-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Execute files
cfs
cfs_nice

# Temporary files
.dependency
*.sh
*.txt

# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
63 changes: 63 additions & 0 deletions scheduler-test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.SUFFIXES: .c .o
.PHONY: dep all new clean

# Compiler
CC = gcc
# Compile option
# -c: Generate object file
# -W, -Wall: Print warning about all ambigous grammer
# -Wextra: Print warning out of -W, -Wall
# -O2: Optimization
# -g: Debugging, PLEASE DELETE AFTER PROJECT COMPLETE!
CFLAGS = -c -W -Wall -Wextra -g $(INC)

# Execute program file
CFS = cfs
CFS_NICE = cfs_nice

# Source file
CFS_SRCS = cfs.c
CFS_NICE_SRCS = cfs_nice.c
SRCS = $(CFS_SRCS) $(CFS_NICE_SRCS)

# Object file
CFS_OBJS = $(CFS_SRCS:.c=.o)
CFS_NICE_OBJS = $(CFS_NICE_SRCS:.c=.o)
OBJS = $(CFS_OBJS) $(CFS_NICE_OBJS)

# Library file
LIBS =

# Include path
INC =

# Execute file grneration
# $@ = TARGET
# $^ = DEPENDENCY
# make all: Make all execute file
all : $(OBJS)
$(CC) -o $(CFS) $(CFS_OBJS) $(LIBS)
$(CC) -o $(CFS_NICE) $(CFS_NICE_OBJS) $(LIBS)
$(CFS) : $(CFS_OBJS)
$(CC) -o $@ $^ $(LIBS)
$(CFS_NICE) : $(CFS_NICE_OBJS)
$(CC) -o $@ $^ $(LIBS)

# Object file generation
$(CFS_OBJS):
$(CC) $(CFLAGS) $(CFS_SRCS)
$(CFS_NICE_OBJS):
$(CC) $(CFLAGS) $(CFS_NICE_SRCS)

# make dep: Make dependency information file
dep:
$(CC) -M $(INC) $(SRCS) > .dependency

# make new: Re-generation
new:
$(MAKE) clean
$(MAKE) all

# make clean: Remove all generated file
clean:
rm -rf $(OBJS) $(CFS) $(CFS_NICE)
150 changes: 150 additions & 0 deletions scheduler-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Scheduler Test

리눅스 커널의 스케줄링 정책을 (기본 CFS, 조정된 NICE 값을 적용한 CFS) 확인할 수 있는 프로그램 작성

## 0. Quick start

``` bash
git clone https://github.com/codejune/c-scheduler-test.git
cd c-scheduler-test

# 일괄 빌드
make

# 개별 빌드
make cfs
./cfs
```

## 1. Environment

### Software

- Ubuntu 20.04.3 LTS (x86_64)
- Linux Kernel 5.11.22

### Hardware

- VM Instance
- 4 Core 8 Thread
- 8 GB RAM
- 60 GB Storage

## 2. Requirement

### 입력

- fork()를 통해 총 21개의 자식 프로세스를 생성

### 조건

- 그룹으로 나누어 Nice 값을 적용하는 CFS의 경우 Nice 값이 낮은 프로세스 그룹부터 우선적으로 수행
- 정책에 뚜렷한 차이가 나타나도록 프로세스는 별도의 단순 연산을 수행
- 생성되는 21개의 프로세스들의 PID들을 프로세스의 생성 및 종료 시점에 출력

### 출력

- 생성되는 프로세스들에게 Nice 값을 조정하지 않고 적용되는 기본 CFS 정책을 적용하는 프로그램
- 생성되는 프로세스들에게 3개의 그룹(높은 Nice 값, 기본 Nice 값, 낮은 Nice 값)으로 나누어 적용하는 CFS 정책을 적용하는 프로그램

### 예시

- 기본 CFS 정책 적용

``` bash
$ ./cfs
Parent running, PID: 274471
++ 1 Child created, PID: 274472
++ 2 Child created, PID: 274473
++ 3 Child created, PID: 274474
++ 6 Child created, PID: 274477
++ 5 Child created, PID: 274476
++ 11 Child created, PID: 274482
++ 4 Child created, PID: 274475
++ 14 Child created, PID: 274485
++ 9 Child created, PID: 274480
++ 10 Child created, PID: 274481
++ 16 Child created, PID: 274487
++ 12 Child created, PID: 274483
++ 13 Child created, PID: 274484
++ 17 Child created, PID: 274488
++ 15 Child created, PID: 274486
++ 18 Child created, PID: 274489
++ 7 Child created, PID: 274478
++ 19 Child created, PID: 274490
++ 8 Child created, PID: 274479
++ 20 Child created, PID: 274491
++ 21 Child created, PID: 274492
-- 16 Child terminated, PID: 274487
-- 11 Child terminated, PID: 274482
-- 4 Child terminated, PID: 274475
-- 7 Child terminated, PID: 274478
-- 10 Child terminated, PID: 274481
-- 3 Child terminated, PID: 274474
-- 9 Child terminated, PID: 274480
-- 14 Child terminated, PID: 274485
-- 18 Child terminated, PID: 274489
-- 20 Child terminated, PID: 274491
-- 1 Child terminated, PID: 274472
-- 2 Child terminated, PID: 274473
-- 6 Child terminated, PID: 274477
-- 12 Child terminated, PID: 274483
-- 15 Child terminated, PID: 274486
-- 8 Child terminated, PID: 274479
-- 17 Child terminated, PID: 274488
-- 19 Child terminated, PID: 274490
-- 5 Child terminated, PID: 274476
-- 21 Child terminated, PID: 274492
-- 13 Child terminated, PID: 274484
Runtime: 1:068653(sec:usec)
```

- 그룹별 NICE 조정 CFS 정책 적용

``` bash
$ ./cfs_nice
Parent running, PID: 274619
++ NICE( 19) Child created, PID: 274620
++ NICE( 19) Child created, PID: 274621
++ NICE( 19) Child created, PID: 274623
++ NICE( 19) Child created, PID: 274622
++ NICE( 0) Child created, PID: 274627
++ NICE( 0) Child created, PID: 274630
++ NICE( 0) Child created, PID: 274632
++ NICE( 0) Child created, PID: 274633
++ NICE( 0) Child created, PID: 274631
++ NICE(-20) Child created, PID: 274637
++ NICE(-20) Child created, PID: 274634
++ NICE( 19) Child created, PID: 274626
++ NICE( 19) Child created, PID: 274625
++ NICE(-20) Child created, PID: 274635
++ NICE( 0) Child created, PID: 274628
++ NICE(-20) Child created, PID: 274636
++ NICE(-20) Child created, PID: 274638
++ NICE( 0) Child created, PID: 274629
++ NICE(-20) Child created, PID: 274639
++ NICE( 19) Child created, PID: 274624
++ NICE(-20) Child created, PID: 274640
-- NICE(-20) Child terminated, PID: 274638
-- NICE(-20) Child terminated, PID: 274637
-- NICE(-20) Child terminated, PID: 274634
-- NICE(-20) Child terminated, PID: 274635
-- NICE(-20) Child terminated, PID: 274639
-- NICE(-20) Child terminated, PID: 274636
-- NICE(-20) Child terminated, PID: 274640
-- NICE( 0) Child terminated, PID: 274629
-- NICE( 0) Child terminated, PID: 274627
-- NICE( 0) Child terminated, PID: 274628
-- NICE( 0) Child terminated, PID: 274630
-- NICE( 0) Child terminated, PID: 274633
-- NICE( 19) Child terminated, PID: 274623
-- NICE( 0) Child terminated, PID: 274632
-- NICE( 0) Child terminated, PID: 274631
-- NICE( 19) Child terminated, PID: 274621
-- NICE( 19) Child terminated, PID: 274620
-- NICE( 19) Child terminated, PID: 274626
-- NICE( 19) Child terminated, PID: 274624
-- NICE( 19) Child terminated, PID: 274625
-- NICE( 19) Child terminated, PID: 274622
Runtime: 3:102885(sec:usec)
```
90 changes: 90 additions & 0 deletions scheduler-test/cfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* @file cfs.c
* @author 김병준 ([email protected])
* @brief 스케줄링 정책 확인을 위한 테스트 프로그램
*/
#include "common.h"

/**
* @brief Main entry function
* @param argc Argument count
* @param argv Argument verse
* @return int Ok 0, Error 1
*/
int main(void)
{
int status;
uint8_t i, j;
uint32_t pid, pid_list[SLAVE_COUNT] = {0};
struct timeval begin_t, end_t;

printf("Parent running, PID: %d\n", getpid());
gettimeofday(&begin_t, NULL);
for (i = 0; i < SLAVE_COUNT; i++)
{
// Process fork
if ((pid = fork()) == (uint32_t)-1)
{
// Occured error: EAGAIN, ENOMEM
perror("Failed to fork");
exit(EXIT_FAILURE);
}
// Child process (PID = 0)
if (pid == 0)
{
printf("++ %2d Child created, PID: %d\n", i + 1, getpid());
product(500);
// sprintf(buf, "chrt -p %d", getpid());
// system(buf);
exit(EXIT_SUCCESS);
}
// Parent process (PID != 0)
else
pid_list[i] = pid;
}

for (i = 0; i < SLAVE_COUNT; i++)
if ((pid = wait(&status)) > 1)
for (j = 0; j < SLAVE_COUNT; j++)
if (pid_list[j] == pid)
printf("-- %2d Child terminated, PID: %d\n", j + 1, pid_list[j]);

gettimeofday(&end_t, NULL);
print_runtime(&begin_t, &end_t);

exit(EXIT_SUCCESS);
}

/**
* @brief Simplified multiplication
* @param n Repeat count
*/
void product(uint64_t n)
{
uint32_t i, j, k;
uint64_t sum = 0;

for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
for (k = 1; k <= n; k++)
sum += i * j * k;
}

/**
* @brief Print running time
* @param begin_t start time
* @param end_t end time
*/
void print_runtime(struct timeval *begin_t, struct timeval *end_t)
{
end_t->tv_sec -= begin_t->tv_sec;

if (end_t->tv_usec < begin_t->tv_usec)
{
end_t->tv_sec--;
end_t->tv_usec += SECOND_TO_MICRO;
}

end_t->tv_usec -= begin_t->tv_usec;
printf("Runtime: %ld:%06ld(sec:usec)\n", end_t->tv_sec, end_t->tv_usec);
}
Loading

0 comments on commit 850114f

Please sign in to comment.