Skip to content

Adding 'sb' instruction to spin_delay() for ARM v8.5 onward #611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

salvatoredipietro
Copy link

We would like to propose this optimization for ARM architecture that, at runtime, it switches to SB instruction if supported by the system. SB (Speculation Barrier) is a modern barrier, available from armv8.5a. It achieves the same result as issuing ISB, but without having the CPU to drop its instruction pipeline.

Our performance evaluation based on 50 repetitions of the attached benchmark (inspired from https://bugs.mysql.com/bug.php?id=74832) conducted on Ubuntu 24.04 on m8g.24xlarge AWS instance using trunk MySQL branch, shows on average up to 28% reduction of the script execution time when sb instruction is used. Also linux perf shows ~11% drop of ut_delay function usage. Here the data:

sudo systemctl restart mysqld.service && sudo systemctl status mysqld.service

echo "Loading"
mysql -u root -pmysql < sql
sleep 5s

echo "Warmup"
for i in {1..5}; do 
    /usr/bin/time  --format="%e real,\t%U user,\t%S sys" ./psdoit 500
    sleep 5s;
done

echo "Benchmark"
for i in {1..50}; do 
    /usr/bin/time  --format="%e real,\t%U user,\t%S sys" --output=psdoit.sb.log --append ./psdoit 500
    sleep 5s;
done


# Results
$ cat psdoit.isb.log  | cut -f1 -d' ' | awk '{sum += $1; count++} END {print sum/count}'
32.445
$ cat psdoit.sb.log  | cut -f1 -d' ' | awk '{sum += $1; count++} END {print sum/count}'
24.504

# Perf ut_delay improvement
## ISB
+   18.87%    18.86%  connection  mysqld [.] ut_delay(unsigned long)

## SB
+    7.76%     7.76%  connection  mysqld  [.] ut_delay(unsigned long)

sql.txt
psdoit.txt

@mysql-oca-bot
Copy link

Hi, thank you for submitting this pull request. In order to consider your code we need you to sign the Oracle Contribution Agreement (OCA). Please review the details and follow the instructions at https://oca.opensource.oracle.com/
Please make sure to include your MySQL bug system user (email) in the returned form.
Thanks

@salvatoredipietro
Copy link
Author

Submitted OCA request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants