10.07.2015 Views

Is Parallel Programming Hard, And, If So, What Can You Do About It?

Is Parallel Programming Hard, And, If So, What Can You Do About It?

Is Parallel Programming Hard, And, If So, What Can You Do About It?

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

D.3. HIERARCHICAL RCU CODE WALKTHROUGH 211−>levelspread[]−>levelcnt[]−>level[]−>node[][0]2[0]1[0][0]parent[1]3[1]2[1][2][3]60[1] parent [2] parentrcu_state−>rda[][0][1][2][3][4][5]mynodemynodemynodemynodemynodemynodeFigure D.26: Initialized RCU Data Layouterarchy. In the figure, therefore, the root node hastwochildrenandthenodesattheleafleveleachhavethree children. Each element of the levelcnt[] arrayindicateshowmanynodesthereareonthecorrespondinglevel of the hierarchy: 1 at the root level,2 at the leaf level, and 6 at the rcu_data level—and any extra elements are unused and left as zero.Each element of the ->level[] array references thefirst node of the corresponding level of the rcu_nodehierarchy, and each element of the ->rda[] arrayreferences the corresponding CPU’s rcu_data structure.The->parentfieldofeachrcu_nodestructurereferences its parent, except for the root rcu_nodestructure, which has a NULL ->parent pointer. Finally,the ->mynode field of each rcu_data structurereferences its parent rcu_node structure.Quick Quiz D.33: How does the code traversea given path through the rcu_node hierarchy fromroot to leaves?Again, the following sections walk through thecode that builds this structure.1 #ifdef CONFIG_RCU_FANOUT_EXACT2 static void __init3 rcu_init_levelspread(struct rcu_state *rsp)4 {5 int i;67 for (i = NUM_RCU_LVLS - 1; i >= 0; i--)8 rsp->levelspread[i] = CONFIG_RCU_FANOUT;9 }10 #else11 static void __init12 rcu_init_levelspread(struct rcu_state *rsp)13 {14 int ccur;15 int cprv;16 int i;1718 cprv = NR_CPUS;19 for (i = NUM_RCU_LVLS - 1; i >= 0; i--) {20 ccur = rsp->levelcnt[i];21 rsp->levelspread[i] = (cprv + ccur - 1) / ccur;22 cprv = ccur;23 }24 }25 #endifD.3.3.1 rcu init levelspread()Figure D.27 shows the code for the rcu_init_levelspread() function, which controls the fanout,or the number of children per parent, in the rcu_node hierarchy. There are two versions of this function,one shown on lines 2-9 that enforces the ex-Figure D.27: rcu init levelspread() Code

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!