├── CODE_OF_CONDUCT.md ├── LICENSE ├── Makefile ├── OSSMETADATA ├── README.md ├── fibtest.c └── runfibtest /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [opensource@indeed.com](mailto:opensource@indeed.com). All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 13 | owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities 16 | that control, are controlled by, or are under common control with that entity. 17 | For the purposes of this definition, "control" means (i) the power, direct or 18 | indirect, to cause the direction or management of such entity, whether by 19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, including 26 | but not limited to software source code, documentation source, and configuration 27 | files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object code, 31 | generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, made 34 | available under the License, as indicated by a copyright notice that is included 35 | in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that 38 | is based on (or derived from) the Work and for which the editorial revisions, 39 | annotations, elaborations, or other modifications represent, as a whole, an 40 | original work of authorship. For the purposes of this License, Derivative Works 41 | shall not include works that remain separable from, or merely link (or bind by 42 | name) to the interfaces of, the Work and Derivative Works thereof. 43 | 44 | "Contribution" shall mean any work of authorship, including the original version 45 | of the Work and any modifications or additions to that Work or Derivative Works 46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 47 | by the copyright owner or by an individual or Legal Entity authorized to submit 48 | on behalf of the copyright owner. For the purposes of this definition, 49 | "submitted" means any form of electronic, verbal, or written communication sent 50 | to the Licensor or its representatives, including but not limited to 51 | communication on electronic mailing lists, source code control systems, and 52 | issue tracking systems that are managed by, or on behalf of, the Licensor for 53 | the purpose of discussing and improving the Work, but excluding communication 54 | that is conspicuously marked or otherwise designated in writing by the copyright 55 | owner as "Not a Contribution." 56 | 57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 58 | of whom a Contribution has been received by Licensor and subsequently 59 | incorporated within the Work. 60 | 61 | 2. Grant of Copyright License. 62 | 63 | Subject to the terms and conditions of this License, each Contributor hereby 64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 65 | irrevocable copyright license to reproduce, prepare Derivative Works of, 66 | publicly display, publicly perform, sublicense, and distribute the Work and such 67 | Derivative Works in Source or Object form. 68 | 69 | 3. Grant of Patent License. 70 | 71 | Subject to the terms and conditions of this License, each Contributor hereby 72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 73 | irrevocable (except as stated in this section) patent license to make, have 74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 75 | such license applies only to those patent claims licensable by such Contributor 76 | that are necessarily infringed by their Contribution(s) alone or by combination 77 | of their Contribution(s) with the Work to which such Contribution(s) was 78 | submitted. If You institute patent litigation against any entity (including a 79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 80 | Contribution incorporated within the Work constitutes direct or contributory 81 | patent infringement, then any patent licenses granted to You under this License 82 | for that Work shall terminate as of the date such litigation is filed. 83 | 84 | 4. Redistribution. 85 | 86 | You may reproduce and distribute copies of the Work or Derivative Works thereof 87 | in any medium, with or without modifications, and in Source or Object form, 88 | provided that You meet the following conditions: 89 | 90 | You must give any other recipients of the Work or Derivative Works a copy of 91 | this License; and 92 | You must cause any modified files to carry prominent notices stating that You 93 | changed the files; and 94 | You must retain, in the Source form of any Derivative Works that You distribute, 95 | all copyright, patent, trademark, and attribution notices from the Source form 96 | of the Work, excluding those notices that do not pertain to any part of the 97 | Derivative Works; and 98 | If the Work includes a "NOTICE" text file as part of its distribution, then any 99 | Derivative Works that You distribute must include a readable copy of the 100 | attribution notices contained within such NOTICE file, excluding those notices 101 | that do not pertain to any part of the Derivative Works, in at least one of the 102 | following places: within a NOTICE text file distributed as part of the 103 | Derivative Works; within the Source form or documentation, if provided along 104 | with the Derivative Works; or, within a display generated by the Derivative 105 | Works, if and wherever such third-party notices normally appear. The contents of 106 | the NOTICE file are for informational purposes only and do not modify the 107 | License. You may add Your own attribution notices within Derivative Works that 108 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 109 | provided that such additional attribution notices cannot be construed as 110 | modifying the License. 111 | You may add Your own copyright statement to Your modifications and may provide 112 | additional or different license terms and conditions for use, reproduction, or 113 | distribution of Your modifications, or for any such Derivative Works as a whole, 114 | provided Your use, reproduction, and distribution of the Work otherwise complies 115 | with the conditions stated in this License. 116 | 117 | 5. Submission of Contributions. 118 | 119 | Unless You explicitly state otherwise, any Contribution intentionally submitted 120 | for inclusion in the Work by You to the Licensor shall be under the terms and 121 | conditions of this License, without any additional terms or conditions. 122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 123 | any separate license agreement you may have executed with Licensor regarding 124 | such Contributions. 125 | 126 | 6. Trademarks. 127 | 128 | This License does not grant permission to use the trade names, trademarks, 129 | service marks, or product names of the Licensor, except as required for 130 | reasonable and customary use in describing the origin of the Work and 131 | reproducing the content of the NOTICE file. 132 | 133 | 7. Disclaimer of Warranty. 134 | 135 | Unless required by applicable law or agreed to in writing, Licensor provides the 136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, 137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 138 | including, without limitation, any warranties or conditions of TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 140 | solely responsible for determining the appropriateness of using or 141 | redistributing the Work and assume any risks associated with Your exercise of 142 | permissions under this License. 143 | 144 | 8. Limitation of Liability. 145 | 146 | In no event and under no legal theory, whether in tort (including negligence), 147 | contract, or otherwise, unless required by applicable law (such as deliberate 148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 149 | liable to You for damages, including any direct, indirect, special, incidental, 150 | or consequential damages of any character arising as a result of this License or 151 | out of the use or inability to use the Work (including but not limited to 152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 153 | any and all other commercial damages or losses), even if such Contributor has 154 | been advised of the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. 157 | 158 | While redistributing the Work or Derivative Works thereof, You may choose to 159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 160 | other liability obligations and/or rights consistent with this License. However, 161 | in accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if You 163 | agree to indemnify, defend, and hold each Contributor harmless for any liability 164 | incurred by, or claims asserted against, such Contributor by reason of your 165 | accepting any such warranty or additional liability. 166 | 167 | END OF TERMS AND CONDITIONS 168 | 169 | APPENDIX: How to apply the Apache License to your work 170 | 171 | To apply the Apache License to your work, attach the following boilerplate 172 | notice, with the fields enclosed by brackets "[]" replaced with your own 173 | identifying information. (Don't include the brackets!) The text should be 174 | enclosed in the appropriate comment syntax for the file format. We also 175 | recommend that a file or class name and description of purpose be included on 176 | the same "printed page" as the copyright notice for easier identification within 177 | third-party archives. 178 | 179 | Copyright [yyyy] [name of copyright owner] 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | 193 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Indeed Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 4 | # in compliance with the License. You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software distributed under the 9 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 10 | # express or implied. See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | # Author: "Dave Chiluk" 14 | 15 | 16 | # Declaration of variables 17 | CC = gcc 18 | CFLAGS ?= -Wall -Werror 19 | # CFLAGS += -std=gnu99 20 | DEFINES = 21 | 22 | # File names 23 | EXEC=fibtest 24 | SOURCES = $(wildcard *.c) 25 | OBJECTS = $(SOURCES:.c=.o) 26 | 27 | # Main target 28 | $(EXEC): $(OBJECTS) 29 | $(CC) -pthread $(OBJECTS) -o $(EXEC) 30 | 31 | %.o: %.c 32 | $(CC) -std=gnu99 -O3 $(CFLAGS) -c $< -o $@ 33 | 34 | clean: 35 | rm -f $(EXEC) $(OBJECTS) 36 | 37 | -------------------------------------------------------------------------------- /OSSMETADATA: -------------------------------------------------------------------------------- 1 | osslifecycle=experimental 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fibtest 2 | 3 | ![OSS Lifecycle](https://img.shields.io/osslifecycle/indeedeng/fibtest.svg) 4 | 5 | Fibtest is a small C application that runs the Fibonacci sequence and reports 6 | how many iterations it completed. 7 | 8 | It spawns fast threads and slow threads. Fast threads run the sequence as fast 9 | as possible. Slow threads run 100 iterations and then sleep for 10ms. Each 10 | thread is pinned to its corresponding CPU (thread 0 is on CPU 0, thread 2 on 11 | CPU 2 etc...). 12 | 13 | By default fibtest spawns one fast thread on CPU 0 and a number of slow 14 | threads equal to the number of CPUs minus the number of fast threads. 15 | 16 | ## Running fibtest 17 | ``` 18 | $ ./runfibtest 1; ./runfibtest 19 | ``` 20 | 21 | `runfibtest` optionally takes an argument for the total number of threads to spawn. With no argument 22 | it will spawn one fast thread and as many slow threads as are equal to one less than the total number of 23 | CPUs. 24 | 25 | It returns the number of iterations of the Fibonacci sequence it was able to accomplish as well as how 26 | long it was throttled and the corresponding CPU usage. 27 | 28 | ## Code of Conduct 29 | This project is governed by the [Contributor Covenant v 1.4.1](CODE_OF_CONDUCT.md) 30 | 31 | ## License 32 | 33 | [Apache License Version 2.0](https://github.com/indeedeng/throttletest/blob/master/LICENSE) 34 | -------------------------------------------------------------------------------- /fibtest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Indeed Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * Author: "Dave Chiluk" 15 | * 16 | * Description: This application runs the fibonacci sequence on multiple 17 | * threads each pinned to a * CPU for a requested amount of time. It then prints 18 | * out the total number of iterations it was able to complete. 19 | */ 20 | 21 | // This is needed for CPU* functions 22 | #define _GNU_SOURCE 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | // Returns number of iterations completed. 35 | static void *fast( void *arg ); 36 | static void *slow( void *arg ); 37 | 38 | // Handle alarm and print number of iterations. 39 | void handle_sigalrm(); 40 | 41 | struct thread_info { 42 | pthread_t thread_id; 43 | unsigned long iterations; 44 | unsigned long fib_res; 45 | }; 46 | 47 | struct timespec endtime; 48 | 49 | void usage () 50 | { 51 | fprintf (stdout, 52 | "Usage: $0 -t \n" 53 | "This application runs the fibonacci sequence on multiple\n" 54 | "threads each pinned to a CPU for a requested amount of time.\n" 55 | "It then prints out the total number of iterations it was able to complete.\n" 56 | "\n" 57 | "It divides execution into fast and slow threads. Fast threads run as fast\n" 58 | "as possible and slow threads run 100 iterations and the sleep for 10ms.\n" 59 | "\n" 60 | "Options\n" 61 | "-v, Verbose prints total number of iterations per thread\n" 62 | "-f , number of fast threads (Default=1).\n" 63 | "-t , total number of threads (Default=Number of CPUs)\n" 64 | "-s , Sets the duration of the test (Default=5 seconds)\n" 65 | ); 66 | } 67 | 68 | int main(int argc, char *argv[]) 69 | { 70 | unsigned long total=0; 71 | int c, num_threads=2, procs, fast_threads=1; 72 | struct thread_info *tinfo; 73 | bool verbose=false; 74 | cpu_set_t cpuset; 75 | int seconds=5; // Default test duration 76 | 77 | // Get the number of processors 78 | // CHILUK: this should handle the case where the task group is pinned to a subset 79 | // of cores. 80 | procs = get_nprocs_conf(); 81 | num_threads = procs; 82 | 83 | // Argument processing. 84 | while ((c = getopt (argc, argv, "vf:t:s:")) != -1) 85 | { 86 | // CHILUK: fix arguements and usage. 87 | switch (c) 88 | { 89 | case 'v': 90 | verbose = true; 91 | break; 92 | case 'f': 93 | fast_threads = (int) strtol(optarg, NULL, 0); 94 | break; 95 | case 't': 96 | num_threads = (int) strtol(optarg, NULL, 0); 97 | break; 98 | case 's': 99 | seconds = (int) strtol(optarg, NULL, 0); 100 | break; 101 | case '?': 102 | default: 103 | usage(); 104 | exit(0); 105 | } 106 | if( num_threads < fast_threads) 107 | num_threads = fast_threads; 108 | } 109 | 110 | tinfo = calloc(num_threads, sizeof(struct thread_info)); 111 | 112 | // Set the end time 113 | if (clock_gettime(CLOCK_REALTIME_COARSE, &endtime )) { 114 | fprintf(stderr, "Unable to get endtime"); 115 | exit(1); 116 | } 117 | endtime.tv_sec += seconds; 118 | 119 | // Spawn requested number of threads 120 | for( int tnum=0; tnum < num_threads; tnum++) { 121 | // CHILUK: check return values 122 | // Balance threads accross cores. 123 | if( tnum % procs < fast_threads ) 124 | pthread_create(&tinfo[tnum].thread_id, NULL, fast, &tinfo[tnum]); 125 | else 126 | pthread_create(&tinfo[tnum].thread_id, NULL, slow, &tinfo[tnum]); 127 | // Set the cpu affinity to tnum%(number of cpus) 128 | CPU_ZERO(&cpuset); 129 | CPU_SET(tnum % procs, &cpuset); 130 | pthread_setaffinity_np(tinfo[tnum].thread_id, sizeof(cpu_set_t), &cpuset ); 131 | } 132 | 133 | // Wait for thread completion. 134 | for( int tnum=0; tnum < num_threads; tnum++) 135 | // CHILUK: check return values 136 | pthread_join(tinfo[tnum].thread_id, NULL); 137 | 138 | // Add up the total number of iterations per thread. 139 | for( int tnum=0; tnum < num_threads; tnum++) 140 | { 141 | if (verbose) 142 | printf("fib[%lu] = %lu \n", tinfo[tnum].iterations, tinfo[tnum].fib_res); 143 | total += tinfo[tnum].iterations; 144 | } 145 | 146 | printf("Iterations Completed(M): %lu \n", total/1000000 ); 147 | free(tinfo); 148 | exit(0); 149 | } 150 | 151 | // Checks to see if we have reached the end of our test time. 152 | bool done() 153 | { 154 | struct timespec cur; 155 | if (clock_gettime( CLOCK_REALTIME_COARSE , &cur)) { 156 | fprintf(stderr, "Unable to get curtime"); 157 | exit(1); 158 | } 159 | if (cur.tv_sec == endtime.tv_sec) 160 | return cur.tv_nsec > endtime.tv_nsec; 161 | else 162 | return cur.tv_sec > endtime.tv_sec; 163 | } 164 | 165 | // Runs the fibonacci sequence 100 iterations at a time then sleeps for 10ms. 166 | static void *slow( void *arg) 167 | { 168 | struct thread_info *tinfo = arg; 169 | long int a=0; 170 | long int b=1; 171 | long int c=0; 172 | long int i=0; 173 | 174 | while( ! done() ) 175 | { 176 | for(int j=0; j< 100; j++) 177 | { 178 | i++; 179 | c=a+b; 180 | a=b; 181 | b=c; 182 | } 183 | usleep ( 10000 ); 184 | } 185 | // We've timed out. 186 | tinfo->iterations=i; 187 | tinfo->fib_res=a; 188 | 189 | return (void *)tinfo; 190 | } 191 | 192 | // Runs the fibonacci sequence 1 million iterations before checking if we've timed out. 193 | static void *fast( void *arg) 194 | { 195 | struct thread_info *tinfo = arg; 196 | long int a=0; 197 | long int b=1; 198 | long int c=0; 199 | long int i=0; 200 | 201 | while( ! done() ) 202 | { 203 | for(int j=0; j< 1000000; j++) 204 | { 205 | i++; 206 | c=a+b; 207 | a=b; 208 | b=c; 209 | } 210 | } 211 | // We've timed out. 212 | tinfo->iterations=i; 213 | tinfo->fib_res=a; 214 | return (void *)tinfo; 215 | } 216 | -------------------------------------------------------------------------------- /runfibtest: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (C) 2019 Indeed Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed under the 11 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | # express or implied. See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Author: "Dave Chiluk" 16 | # set -euo pipefail 17 | 18 | CGROUP=user.slice/fibtest 19 | CGROUPDIR=/sys/fs/cgroup/cpu,cpuacct 20 | typeset -i BNRTHROTT ANRTHROTT DNRTHROTT AUSAGE BUSAGE DUSAGE THREADS NRCPUS THREADEDIT THREADEDTIME THREADEDTHROT SINGLEIT SINGLETIME SINGLETHROT 21 | NRCPUS=$(getconf _NPROCESSORS_ONLN) 22 | THREADS=${1:-NRCPUS} 23 | QUOTA=$(( 10000 )) 24 | 25 | checkandcompile () { 26 | if [ ! -x fibtest ] ; then 27 | make clean 28 | make 29 | if [ ! -x fibtest ] ; then 30 | echo "Unable to compile fibtest\n" 31 | exit 1 32 | fi 33 | fi 34 | } 35 | 36 | # Save old governors, and assume all governors match 37 | savegovernors () { 38 | OLDGOV=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) 39 | OLDENERGY=$(cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference) 40 | } 41 | 42 | # Set governors 43 | setgovernors () { 44 | SCALINGGOV=$1 45 | ENERGYGOV=$2 46 | 47 | for (( i=0 ; i < NRCPUS ; i++ )) 48 | do 49 | sudo sh -c "echo '$SCALINGGOV' > /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor" 50 | sudo sh -c "echo '$ENERGYGOV' > /sys/devices/system/cpu/cpu${i}/cpufreq/energy_performance_preference" 51 | done 52 | } 53 | 54 | runtest () { 55 | BNRTHROTT=$(grep nr_throttled ${CGROUPDIR}/${CGROUP}/cpu.stat | awk '{print $2}') 56 | BUSAGE=$(cat ${CGROUPDIR}/${CGROUP}/cpuacct.usage) 57 | 58 | ##### RUN TEST ##### 59 | ITERATIONS=$(./fibtest -t "$THREADS" -s 5 | awk -F': ' '{print $2}' ) 60 | echo "Iterations Completed(M): $ITERATIONS" 61 | ANRTHROTT=$(grep nr_throttled ${CGROUPDIR}/${CGROUP}/cpu.stat | awk '{print $2}') 62 | AUSAGE=$(cat ${CGROUPDIR}/${CGROUP}/cpuacct.usage) 63 | DNRTHROTT=$(( ANRTHROTT - BNRTHROTT )) 64 | DUSAGE=$(( AUSAGE - BUSAGE )) 65 | echo "Throttled for: $DNRTHROTT " 66 | echo "CPU Usage (msecs) = $((DUSAGE / 1000000 ))" 67 | } 68 | 69 | 70 | checkandcompile 71 | savegovernors 72 | setgovernors performance performance 73 | 74 | # Create CGROUP 75 | if [ ! -d ${CGROUPDIR}/${CGROUP} ] ; then 76 | sudo mkdir -p ${CGROUPDIR}/${CGROUP} 77 | fi 78 | 79 | # Set the CPU quota 80 | sudo sh -c "echo $QUOTA > ${CGROUPDIR}/${CGROUP}/cpu.cfs_quota_us" 81 | sudo sh -c "echo $$ >> ${CGROUPDIR}/${CGROUP}/tasks" 82 | 83 | # ****************** RUN THE TEST *************** 84 | # Uses Number of CPUs 85 | runtest 86 | # 87 | THREADEDIT=${ITERATIONS} 88 | 89 | 90 | # *********************************************** 91 | 92 | setgovernors "${OLDGOV}" "${OLDENERGY}" 93 | --------------------------------------------------------------------------------