Skip to content

Commit

Permalink
make ns_per_tsc arch-dependent
Browse files Browse the repository at this point in the history
Change-Id: I8870ae0ce75624fa587e21c9fd24e68c33f0ef34
Fujitsu: POSTK_DEBUG_ARCH_DEP_29
Refs: #1352
  • Loading branch information
stkn-hse authored and masamichitakagi committed Sep 26, 2019
1 parent d5dc163 commit ec2472d
Show file tree
Hide file tree
Showing 10 changed files with 307 additions and 11 deletions.
2 changes: 0 additions & 2 deletions linux/driver/smp/arch/arm64/smp-arch-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,6 @@ int smp_wakeup_secondary_cpu(int hw_id, unsigned long start_eip)
return ihk_psci_ops->cpu_on(affi, start_eip);
}

#ifdef POSTK_DEBUG_ARCH_DEP_29
unsigned long calc_ns_per_tsc(void)
{
unsigned int freq;
Expand All @@ -898,7 +897,6 @@ unsigned long calc_ns_per_tsc(void)

return 1000000000000L / freq;
}
#endif /* POSTK_DEBUG_ARCH_DEP_29 */

#ifdef CONFIG_ARM64_SVE
unsigned long get_sve_default_vl(void)
Expand Down
28 changes: 25 additions & 3 deletions linux/driver/smp/arch/x86_64/smp-arch-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,34 @@ int smp_wakeup_secondary_cpu(int apicid, unsigned long start_eip)
}
}

#ifdef POSTK_DEBUG_ARCH_DEP_29
unsigned long calc_ns_per_tsc(void)
{
return 1000000000L / tsc_khz;
unsigned long msr, ret;
unsigned int ratio;
uint64_t op;
uint64_t eax;
uint64_t ebx;
uint64_t ecx;
uint64_t edx;

op = 0x80000007;
asm volatile("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx),
"=d"(edx) : "a" (op));

if (edx & (1 << 8)) {
/* Invariant TSC supported */
/* ratio (100MHz) */
rdmsrl(MSR_PLATFORM_INFO, msr);
ratio = (msr >> 8) & 0xFF;

ret = 10000 / ratio;
}
else {
ret = 1000000000L / tsc_khz;
}

return ret;
}
#endif /* POSTK_DEBUG_ARCH_DEP_29 */

unsigned long x2apic_is_enabled(void)
{
Expand Down
2 changes: 0 additions & 2 deletions linux/driver/smp/smp-arch-driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@

int ihk_smp_get_hw_id(int cpu);
int smp_wakeup_secondary_cpu(int hw_id, unsigned long start_eip);
#ifdef POSTK_DEBUG_ARCH_DEP_29
unsigned long calc_ns_per_tsc(void);
#endif /* POSTK_DEBUG_ARCH_DEP_29 */
void smp_ihk_setup_trampoline(void *priv);
unsigned long smp_ihk_adjust_entry(unsigned long entry,
unsigned long phys);
Expand Down
4 changes: 0 additions & 4 deletions linux/driver/smp/smp-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,7 @@ bp_cpu->numa_id = linux_numa_2_lwk_numa(os,
os->param->msg_buffer_size = sizeof(struct ihk_kmsg_buf); /* Note that it's used for map_fixed_area */
dprintk("%s: msg_buffer=%lx,size=%ld\n", __FUNCTION__, os->param->msg_buffer, os->param->msg_buffer_size);

#ifdef POSTK_DEBUG_ARCH_DEP_29
os->param->ns_per_tsc = calc_ns_per_tsc();
#else /* POSTK_DEBUG_ARCH_DEP_29 */
os->param->ns_per_tsc = 1000000000L / tsc_khz;
#endif /* POSTK_DEBUG_ARCH_DEP_29 */
getnstimeofday(&now);
os->param->boot_tsc = rdtsc();
os->param->boot_sec = now.tv_sec;
Expand Down
47 changes: 47 additions & 0 deletions test/issues/1352/C1352.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#/bin/sh

USELTP=1
USEOSTEST=0

. ../../../../mckernel/test/common.sh

issue=1352
tid=01

arch=`uname -p`
if [ "${arch}" == "x86_64" ]; then
sudo tail -n 30 /var/log/messages > ./msg_after_mcreboot.txt
fi

for tp in futex_wait01 futex_wait02 futex_wait03 futex_wait04 \
futex_wait_bitset01 futex_wait_bitset02 \
futex_wake01 futex_wake02 futex_wake03
do
tname=`printf "C${issue}T%02d" ${tid}`
echo "*** ${tname} start *******************************"
$MCEXEC $LTPBIN/$tp 2>&1 | tee $tp.txt
ok=`grep TPASS $tp.txt | wc -l`
ng=`grep TFAIL $tp.txt | wc -l`
if [ $ng = 0 ]; then
echo "*** ${tname} PASSED ($ok)"
else
echo "*** ${tname} FAILED (ok=$ok ng=%ng)"
fi
let tid++
echo ""
done

if [ "${arch}" == "x86_64" ]; then
tname=`printf "C${issue}T%02d" ${tid}`
echo "*** ${tname} start *******************************"
grep "TSC_.*:" ./msg_after_mcreboot.txt
ok=`grep "TSC_OK" ./msg_after_mcreboot.txt | wc -l`
ng=`grep "TSC_NG" ./msg_after_mcreboot.txt | wc -l`
if [ $ok = 2 ]; then
echo "*** ${tname} PASSED ($ok)"
else
echo "*** ${tname} FAILED (ok=$ok ng=%ng)"
fi
let tid++
echo ""
fi
11 changes: 11 additions & 0 deletions test/issues/1352/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CFLAGS=-g
LDFLAGS=

TARGET=

all: $(TARGET)

test: all
./C1352.sh
clean:
rm -f $(TARGET) *.o *.txt
37 changes: 37 additions & 0 deletions test/issues/1352/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
【Issue#1352 動作確認】
□ テスト内容
1. ns_per_tscを用いるfutexの既存処理に影響しないことを確認
以下のLTPがPASSすることを確認
- futex_wait01
- futex_wait02
- futex_wait03
- futex_wait04
- futex_wait_bitset01
- futex_wait_bitset02
- futex_wake01
- futex_wake02
- futex_wake03

2. MSR_PLATFORM_INFO から取得したratioの確認 (x86_64アーキテクチャのみで実施)
MSR_PLATFORM_INFOから取得したratioと、kernelが保持している
tsc_khz の値を比較し、誤差が±0.01%の範囲内であることを確認する
また、ratioから算出されたns_per_tscが、tsc_khzから算出された
tscと一致することを確認する

□ 実行手順
1. 下記の手順でテストを実行する
$ cd <ihk>
$ patch -p0 < test/issues/1352/comp_ratio_to_tsc_khz.patch
(build mckernel)
$ cd test/issues/1352
$ make test

McKernelのインストール先や、OSTEST, LTPの配置場所は、
$HOME/.mck_test_config を参照している
.mck_test_config は、McKernelをビルドした際に生成されるmck_test_config.sample ファイルを
$HOMEにコピーし、適宜編集する

□ 実行結果
x86_64_result.log aarch64_result.log 参照
すべての項目をPASSしていることを確認。

72 changes: 72 additions & 0 deletions test/issues/1352/aarch64_result.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
*** C1352T01 start *******************************
futex_wait01 1 TPASS : futex_wait(): errno=ETIMEDOUT(110): Connection timed out
futex_wait01 2 TPASS : futex_wait(): errno=EAGAIN/EWOULDBLOCK(11): Resource temporarily unavailable
futex_wait01 3 TPASS : futex_wait(): errno=ETIMEDOUT(110): Connection timed out
futex_wait01 4 TPASS : futex_wait(): errno=EAGAIN/EWOULDBLOCK(11): Resource temporarily unavailable
*** C1352T01 PASSED (4)

*** C1352T02 start *******************************
futex_wait02 1 TPASS : futex_wait() woken up
*** C1352T02 PASSED (1)

*** C1352T03 start *******************************
futex_wait03 1 TPASS : futex_wait() woken up
*** C1352T03 PASSED (1)

*** C1352T04 start *******************************
futex_wait04 1 TPASS : futex_wait() returned -1: errno=EAGAIN/EWOULDBLOCK(11): Resource temporarily unavailable
*** C1352T04 PASSED (1)

*** C1352T05 start *******************************
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s
futex_wait_bitset.h:17: INFO: testing futex_wait_bitset() timeout with CLOCK_MONOTONIC
futex_wait_bitset.h:59: PASS: futex_wait_bitset() waited 101746us, expected 100010us

Summary:
passed 1
failed 0
skipped 0
warnings 0
*** C1352T05 PASSED (0)

*** C1352T06 start *******************************
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s
futex_wait_bitset.h:17: INFO: testing futex_wait_bitset() timeout with CLOCK_REALTIME
futex_wait_bitset.h:59: PASS: futex_wait_bitset() waited 102127us, expected 100010us

Summary:
passed 1
failed 0
skipped 0
warnings 0
*** C1352T06 PASSED (0)

*** C1352T07 start *******************************
futex_wake01 1 TPASS : futex_wake() returned 0
futex_wake01 2 TPASS : futex_wake() returned 0
futex_wake01 3 TPASS : futex_wake() returned 0
futex_wake01 4 TPASS : futex_wake() returned 0
futex_wake01 5 TPASS : futex_wake() returned 0
futex_wake01 6 TPASS : futex_wake() returned 0
*** C1352T07 PASSED (6)

*** C1352T08 start *******************************
futex_wake02 1 TBROK : futex_wake02.c:79: pthread_create(): EAGAIN/EWOULDBLOCK
futex_wake02 2 TBROK : futex_wake02.c:79: Remaining cases broken
futex_wake02 0 TINFO : Child process returned TBROK
*** C1352T08 PASSED (0)

*** C1352T09 start *******************************
futex_wake03 1 TPASS : futex_wake() woken up 1 childs
futex_wake03 2 TPASS : futex_wake() woken up 2 childs
futex_wake03 3 TPASS : futex_wake() woken up 3 childs
futex_wake03 4 TPASS : futex_wake() woken up 4 childs
futex_wake03 5 TPASS : futex_wake() woken up 5 childs
futex_wake03 6 TPASS : futex_wake() woken up 6 childs
futex_wake03 7 TPASS : futex_wake() woken up 7 childs
futex_wake03 8 TPASS : futex_wake() woken up 8 childs
futex_wake03 9 TPASS : futex_wake() woken up 9 childs
futex_wake03 10 TPASS : futex_wake() woken up 10 childs
futex_wake03 11 TPASS : futex_wake() woken up 0 children
*** C1352T09 PASSED (11)

29 changes: 29 additions & 0 deletions test/issues/1352/comp_ratio_to_tsc_khz.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git linux/driver/smp/arch/x86_64/smp-arch-driver.c linux/driver/smp/arch/x86_64/smp-arch-driver.c
index 6838980..a3001eb 100644
--- linux/driver/smp/arch/x86_64/smp-arch-driver.c
+++ linux/driver/smp/arch/x86_64/smp-arch-driver.c
@@ -369,6 +369,24 @@ unsigned long calc_ns_per_tsc(void)
ratio = (msr >> 8) & 0xFF;

ret = 10000 / ratio;
+
+ /* THIS IS TEST-CODE FOR ISSUE_1352 */
+ /* check if ratio is nearly equal tsc_khz */
+ unsigned long ratio_khz = ratio * 100000;
+ unsigned long expect_tsc = 1000000000L / tsc_khz; // calc by tsc_khz
+ if ((ratio_khz > tsc_khz * 0.9999) && (ratio_khz < tsc_khz * 1.0001)) {
+ printk("TSC_OK: ratio is nearly equal to tsc_khz\n");
+ }
+ else {
+ printk("TSC_NG: ratio is NOT correct\n");
+ }
+ if (expect_tsc == ret) {
+ printk("TSC_OK: ns_per_tsc value is as expected\n");
+ }
+ else {
+ printk("TSC_NG: ns_per_tsc value is NOT as expected\n");
+ }
+
}
else {
ret = 1000000000L / tsc_khz;
86 changes: 86 additions & 0 deletions test/issues/1352/x86_64_result.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
*** C1352T01 start *******************************
futex_wait01 1 TPASS : futex_wait(): errno=ETIMEDOUT(110): Connection timed out
futex_wait01 2 TPASS : futex_wait(): errno=EAGAIN/EWOULDBLOCK(11): Resource temporarily unavailable
futex_wait01 3 TPASS : futex_wait(): errno=ETIMEDOUT(110): Connection timed out
futex_wait01 4 TPASS : futex_wait(): errno=EAGAIN/EWOULDBLOCK(11): Resource temporarily unavailable
*** C1352T01 PASSED (4)

*** C1352T02 start *******************************
futex_wait02 1 TPASS : futex_wait() woken up
*** C1352T02 PASSED (1)

*** C1352T03 start *******************************
futex_wait03 1 TPASS : futex_wait() woken up
*** C1352T03 PASSED (1)

*** C1352T04 start *******************************
futex_wait04 1 TPASS : futex_wait() returned -1: errno=EAGAIN/EWOULDBLOCK(11): Resource temporarily unavailable
*** C1352T04 PASSED (1)

*** C1352T05 start *******************************
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s
futex_wait_bitset.h:17: INFO: testing futex_wait_bitset() timeout with CLOCK_MONOTONIC
futex_wait_bitset.h:59: PASS: futex_wait_bitset() waited 144495us, expected 100010us

Summary:
passed 1
failed 0
skipped 0
warnings 0
*** C1352T05 PASSED (0)

*** C1352T06 start *******************************
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s
futex_wait_bitset.h:17: INFO: testing futex_wait_bitset() timeout with CLOCK_REALTIME
futex_wait_bitset.h:59: PASS: futex_wait_bitset() waited 144501us, expected 100010us

Summary:
passed 1
failed 0
skipped 0
warnings 0
*** C1352T06 PASSED (0)

*** C1352T07 start *******************************
futex_wake01 1 TPASS : futex_wake() returned 0
futex_wake01 2 TPASS : futex_wake() returned 0
futex_wake01 3 TPASS : futex_wake() returned 0
futex_wake01 4 TPASS : futex_wake() returned 0
futex_wake01 5 TPASS : futex_wake() returned 0
futex_wake01 6 TPASS : futex_wake() returned 0
*** C1352T07 PASSED (6)

*** C1352T08 start *******************************
futex_wake02 1 TPASS : futex_wake() woken up 1 threads
futex_wake02 2 TPASS : futex_wake() woken up 2 threads
futex_wake02 3 TPASS : futex_wake() woken up 3 threads
futex_wake02 4 TPASS : futex_wake() woken up 4 threads
futex_wake02 5 TPASS : futex_wake() woken up 5 threads
futex_wake02 6 TPASS : futex_wake() woken up 6 threads
futex_wake02 7 TPASS : futex_wake() woken up 7 threads
futex_wake02 8 TPASS : futex_wake() woken up 8 threads
futex_wake02 9 TPASS : futex_wake() woken up 9 threads
futex_wake02 10 TPASS : futex_wake() woken up 10 threads
futex_wake02 11 TPASS : futex_wake() woken up 0 threads
futex_wake02 0 TINFO : Child process returned TPASS
*** C1352T08 PASSED (12)

*** C1352T09 start *******************************
futex_wake03 1 TPASS : futex_wake() woken up 1 childs
futex_wake03 2 TPASS : futex_wake() woken up 2 childs
futex_wake03 3 TPASS : futex_wake() woken up 3 childs
futex_wake03 4 TPASS : futex_wake() woken up 4 childs
futex_wake03 5 TPASS : futex_wake() woken up 5 childs
futex_wake03 6 TPASS : futex_wake() woken up 6 childs
futex_wake03 7 TPASS : futex_wake() woken up 7 childs
futex_wake03 8 TPASS : futex_wake() woken up 8 childs
futex_wake03 9 TPASS : futex_wake() woken up 9 childs
futex_wake03 10 TPASS : futex_wake() woken up 10 childs
futex_wake03 11 TPASS : futex_wake() woken up 0 children
*** C1352T09 PASSED (11)

*** C1352T10 start *******************************
Sep 15 14:43:12 wallaby12 kernel: TSC_OK: ratio is nearly equal to tsc_khz
Sep 15 14:43:12 wallaby12 kernel: TSC_OK: ns_per_tsc value is as expected
*** C1352T10 PASSED (2)

0 comments on commit ec2472d

Please sign in to comment.