{"id":48356838,"url":"https://github.com/green-coding-solutions/tools","last_synced_at":"2026-04-05T11:33:41.617Z","repository":{"id":104088539,"uuid":"517583855","full_name":"green-coding-solutions/tools","owner":"green-coding-solutions","description":"Small scripts and prototypes for energy measurement","archived":false,"fork":false,"pushed_at":"2025-08-23T08:32:02.000Z","size":56,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-24T03:04:14.006Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Assembly","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/green-coding-solutions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2022-07-25T08:39:18.000Z","updated_at":"2025-05-13T11:23:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"e4a4a035-5056-4b33-8ca6-e816757b919a","html_url":"https://github.com/green-coding-solutions/tools","commit_stats":null,"previous_names":["green-coding-solutions/tools"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/green-coding-solutions/tools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/green-coding-solutions%2Ftools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/green-coding-solutions%2Ftools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/green-coding-solutions%2Ftools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/green-coding-solutions%2Ftools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/green-coding-solutions","download_url":"https://codeload.github.com/green-coding-solutions/tools/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/green-coding-solutions%2Ftools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31434624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T08:13:15.228Z","status":"ssl_error","status_checked_at":"2026-04-05T08:13:11.839Z","response_time":75,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-04-05T11:33:41.451Z","updated_at":"2026-04-05T11:33:41.580Z","avatar_url":"https://github.com/green-coding-solutions.png","language":"Assembly","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tools\nSmall scripts and prototypes for energy measurement\n\n\n## MSR configurations\n\n### turbo_boost.sh\nThis script can turn the TurboBoost feature in Intel CPUs on or off.\n\nAccording to [Brendan Greggs MSR-Tools Repo](https://github.com/brendangregg/msr-cloud-tools/blob/master/showboost) there might be some registers to \nbe called when running on different Intel CPUs.\n\nWe could not test it on all the possbile, therefore we can only guarantee\nfunctionality for Intel Core i7 with Broadwell architecture.\n\nIf our script will not work check out the correct register with Brendan Greggs script.\n\n### RAPL energy filtering\n\nThe RAPL accuracy can be be lowered by either having SGX turned on OR by activating\nan option in Intel CPUs called \"energy filtering\".\n\nSource: [https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/advisory-guidance/running-average-power-limit-energy-reporting.html#ipu-2020.2](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/advisory-guidance/running-average-power-limit-energy-reporting.html#ipu-2020.2)\n\nWhat actually happens is that the energy information returned by RAPL is randomly modified\nand will be 0-50% different from the original signal.\n\nThis is enough to still have a broad idea of what the total energy budget is but prevents\nenergy side-channel attacks.\n\nWe include a script that can check if the energy filtering switch has been set:\n\n`sudo check_energy_filtering_rapl.sh`\n\n#### Test SGX\n\nThe other possible option when energy filtering kicks in is if **SGX** is activated\nin the BIOS. You don't have to have the SGX libraries installed ... just the BIOS\nswitch suffices.\n\nTo test wether SGX is activeuse \nthe following script:\n\n`gcc test-sgx.c \u0026\u0026 ./a.out`\n\nThe relevat values to look at are:\n```bash\nsgx available: 0\nsgx launch control: 0\n```\nONLY if both of them are 1, then SGX is active.\n\n**Credits:** This beautiful script has been copied from [@ayeks](https://github.com/ayeks/SGX-hardware)! Be sure to have a look at the repo!\n\n### cpu_relax\n\nThis script will trigger same logic as the `cpu_relax()` function in the linux kernel does.\n\nOriginally designed for spin-locks this function can set the processor cycling on \nthe lowest power instruction without loosing control of it (C-State, scheduling etc.)\n\n### DVFS\n\nThis script will change the cpu frequency govenor in the linux system.\n\nCurrently it will just switch to **schedutil** / **performance** or **powersave**.\n\nThe possible govenors you can find in:\n`/sys/devices/system/cpu/cpuX/cpufreq/scaling_available_governors`\n\nCheck if the frequency was really changed by: `watch -d -n 1 \"cat /proc/cpuinfo | grep MHz\"`\n\n### Read CPU sysbench\n\nIn order for this script to work paranoid level should be set to 0:\n\n`sudo sysctl -w kernel.perf_event_paranoid=0`\n\nIf you run multiple *perf_events* instances it may happen that the counters get multiplexed.\nA warning will be issued in this case.\n\nThe script was designed to find out the deviation between time sharding and instruction sharding\nwhen the system background load or is idling.\n\nCurrently we see the instruction share strongly deviationg from the time share of \na process when the system is loaded.\n\nFurther research has to be done to conclude if one or the other metric is more helpful\nwhen trying to attribte cumulative metrics like energy to a process.\n\n### nop / pause\n\nThe *nop* instruction is the typical \"do nothing\" instruction in the x86 instruction set.\n\nHowever Intel introduced also the *pause* instruction which should be used preferrably\nwhen having the CPU in a spin-lock state. \nThis instruction will hint the processor that a spin-lock is happening and \ncan prevent memory violations and in turn save energy.\n\nIn order to create this code you should compile the `empty_loop.c` with: \n`gcc -S empty_loop.c` option. \nThis will create an assembler file and you have to inject the `nop`/`pause` \nstatements at the correct line.\n\nWe have included sample `*.s` files to showcase that. However they might not compile \ndirectly on your system and should just serve as an example.\n\nOnce you have compiled your own `*.s` file create the executable via: `gcc nop.s`\n\nOn our test machine the energy difference is the following:\n- sudo perf stat -a -e power/energy-pkg/ --timeout 10000 sleep 20\n    + 21.80 Joules\n- sudo perf stat -a -e power/energy-pkg/ ./nop\n    + 87.37 Joules\n    + 89.07 Joules\n    + 86.97 Joules\n- sudo perf stat -a -e power/energy-pkg/ --timeout 10000 ./pause\n    + 88.05 Joules\n    + 89.79 Joules\n    + 88.51 Joules\n    \n#### Benchmarking an unknown CPU with the nop script\n\nIf you want to find out if the CPU speed advertised in the `/proc/cpuinfo` is really\naccurate you can just run the `nop` script and time it.\n\nBy dividing the runtime through the estimated instructions per cycle (either 3 or 4 on modern CPUs)\nyou can find out if the CPU has the expected cycle count.\n\nThe core should get fully loaded and burst to its maximum frequency as the script\ncontains no sleeps.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreen-coding-solutions%2Ftools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreen-coding-solutions%2Ftools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreen-coding-solutions%2Ftools/lists"}