{"id":13441527,"url":"https://github.com/Kobzol/hardware-effects","last_synced_at":"2025-03-20T12:31:21.983Z","repository":{"id":50556645,"uuid":"157026310","full_name":"Kobzol/hardware-effects","owner":"Kobzol","description":"Demonstration of various hardware effects.","archived":false,"fork":false,"pushed_at":"2024-02-29T22:23:18.000Z","size":106,"stargazers_count":2832,"open_issues_count":10,"forks_count":159,"subscribers_count":95,"default_branch":"master","last_synced_at":"2024-10-22T09:51:46.343Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kobzol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-10T22:15:37.000Z","updated_at":"2024-10-21T20:31:30.000Z","dependencies_parsed_at":"2024-10-03T09:51:05.661Z","dependency_job_id":"43385197-f88a-4a71-8843-a35921e1048e","html_url":"https://github.com/Kobzol/hardware-effects","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kobzol%2Fhardware-effects","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kobzol%2Fhardware-effects/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kobzol%2Fhardware-effects/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kobzol%2Fhardware-effects/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kobzol","download_url":"https://codeload.github.com/Kobzol/hardware-effects/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221760026,"owners_count":16876338,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:35.080Z","updated_at":"2025-03-20T12:31:21.971Z","avatar_url":"https://github.com/Kobzol.png","language":"C++","funding_links":[],"categories":["C++","Troubleshooting"],"sub_categories":["Benchmarks"],"readme":"# Hardware effects\nThis repository demonstrates various hardware effects that can degrade application performance\nin surprising ways and that may be very hard to explain without knowledge of the low-level CPU and OS architecture.\nFor each effect I try to create a proof of concept program that is as small as possible so that it can\nbe understood easily.\n\nYou can check out my [talk](https://www.youtube.com/watch?v=ICKIMHCw--Y) about hardware effects from the Meeting C++ 2019 conference.\n\nRelated repository with GPU hardware effects: https://github.com/kobzol/hardware-effects-gpu\n\nThose effects obviously depend heavily on your CPU microarchitecture and model,\nso the demonstration programs may not showcase the slowdown on your CPU, but I try to make\nthem as general as I can. That said, the examples are targeting x86-64 processors (Intel and AMD)\nand may not make sense on other CPU architectures. I focus on effects that should be observable on\ncommodity (desktop/notebook) hardware, so I don't include things like NUMA effects here\n(although in a few years they might be common even in personal computers). The code is mainly tested on Linux.\n\nCurrently the following effects are demonstrated:\n\n- 4k aliasing\n- bandwidth saturation\n- branch misprediction\n- branch target misprediction\n- cache conflicts\n- cache/memory hierarchy bandwidth\n- data dependencies\n- denormal floating point numbers\n- DRAM refresh interval\n- false sharing\n- hardware prefetching\n- hardware store elimination\n- memory-bound program\n- misaligned accesses\n- non-temporal stores\n- software prefetching\n- store buffer capacity\n- write combining\n\nEvery example directory has a README that explains the individual effects.\n\nIsolating those hardware effects can be very tricky, so it's possible that some of the\nexamples are actually demonstrating something entirely else (or nothing at all :) ).\nIf you have a better explanation of what is happening, please let me know in the issues.\nIdeally the code should be written in assembly, however that would lower its readability.\nI wrote it in C++ in a way that (hopefully) forces the compiler to emit the instructions that I want (even with -O3).\n\n### Benchmarking\n\nFor all benchmarks I recommend to turn off frequency scaling, hyper-threading, Turbo mode, address space randomization and\nother stuff that can increase noise. I'm using the following commands:\n```bash\n$ sudo bash -c \"echo 0 \u003e /proc/sys/kernel/randomize_va_space\"           # address randomization\n$ sudo bash -c \"echo 1 \u003e /sys/devices/system/cpu/intel_pstate/no_turbo\" # Turbo mode\n$ sudo bash -c \"echo 0 \u003e /sys/devices/system/cpu/cpuX/online\"           # hyper-threading\n$ ...                                                                   # for all hyper-threading CPUs\n$ sudo cpupower frequency-set --governor performance                    # frequency scaling\n```\n\nYou can find more tips [here](https://llvm.org/docs/Benchmarking.html).\n\n### Build\n```bash\n$ mkdir build\n$ cd build\n$ cmake -DCMAKE_BUILD_TYPE=Release ..\n$ make -j\n```\n\nIf you want to use the benchmark scripts (written in Python 3), you should\nalso install the Python dependencies:\n```bash\n$ pip install -r requirements.txt\n```\n\n### Docker\nYou can download a prebuilt image:\n```bash\n$ docker pull kobzol/hardware-effects\n```\nor build it yourself:\n```bash\n$ docker build -t hardware-effects .\n```\n\nThen run it:\n```bash\n# interactive run\n$ docker run --rm -it hardware-effects\n\n# directly launch a program\n$ docker run hardware-effects build/branch-misprediction/branch-misprediction 1\n```\n\n### License\nMIT\n\n### Resources\n- https://software.intel.com/en-us/download/intel-64-and-ia-32-architectures-optimization-reference-manual\n- https://akkadia.org/drepper/cpumemory.pdf\n- http://igoro.com/archive/gallery-of-processor-cache-effects/\n- https://mechanical-sympathy.blogspot.com\n- https://manybutfinite.com/category/software-illustrated/\n- https://randomascii.wordpress.com/\n- https://www.agner.org/optimize/\n- https://software.intel.com/en-us/articles/intel-sdm#combined\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKobzol%2Fhardware-effects","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKobzol%2Fhardware-effects","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKobzol%2Fhardware-effects/lists"}