@@ -75,14 +75,32 @@ static DEFINE_PER_CPU(int, cpu_state) = { 0 };
7575#endif
7676
7777struct thread_info * secondary_ti ;
78+ bool has_big_cores ;
7879
7980DEFINE_PER_CPU (cpumask_var_t , cpu_sibling_map );
81+ DEFINE_PER_CPU (cpumask_var_t , cpu_smallcore_map );
8082DEFINE_PER_CPU (cpumask_var_t , cpu_l2_cache_map );
8183DEFINE_PER_CPU (cpumask_var_t , cpu_core_map );
8284
8385EXPORT_PER_CPU_SYMBOL (cpu_sibling_map );
8486EXPORT_PER_CPU_SYMBOL (cpu_l2_cache_map );
8587EXPORT_PER_CPU_SYMBOL (cpu_core_map );
88+ EXPORT_SYMBOL_GPL (has_big_cores );
89+
90+ #define MAX_THREAD_LIST_SIZE 8
91+ #define THREAD_GROUP_SHARE_L1 1
92+ struct thread_groups {
93+ unsigned int property ;
94+ unsigned int nr_groups ;
95+ unsigned int threads_per_group ;
96+ unsigned int thread_list [MAX_THREAD_LIST_SIZE ];
97+ };
98+
99+ /*
100+ * On big-cores system, cpu_l1_cache_map for each CPU corresponds to
101+ * the set its siblings that share the L1-cache.
102+ */
103+ DEFINE_PER_CPU (cpumask_var_t , cpu_l1_cache_map );
86104
87105/* SMP operations for this machine */
88106struct smp_ops_t * smp_ops ;
@@ -675,6 +693,185 @@ static void set_cpus_unrelated(int i, int j,
675693}
676694#endif
677695
696+ /*
697+ * parse_thread_groups: Parses the "ibm,thread-groups" device tree
698+ * property for the CPU device node @dn and stores
699+ * the parsed output in the thread_groups
700+ * structure @tg if the ibm,thread-groups[0]
701+ * matches @property.
702+ *
703+ * @dn: The device node of the CPU device.
704+ * @tg: Pointer to a thread group structure into which the parsed
705+ * output of "ibm,thread-groups" is stored.
706+ * @property: The property of the thread-group that the caller is
707+ * interested in.
708+ *
709+ * ibm,thread-groups[0..N-1] array defines which group of threads in
710+ * the CPU-device node can be grouped together based on the property.
711+ *
712+ * ibm,thread-groups[0] tells us the property based on which the
713+ * threads are being grouped together. If this value is 1, it implies
714+ * that the threads in the same group share L1, translation cache.
715+ *
716+ * ibm,thread-groups[1] tells us how many such thread groups exist.
717+ *
718+ * ibm,thread-groups[2] tells us the number of threads in each such
719+ * group.
720+ *
721+ * ibm,thread-groups[3..N-1] is the list of threads identified by
722+ * "ibm,ppc-interrupt-server#s" arranged as per their membership in
723+ * the grouping.
724+ *
725+ * Example: If ibm,thread-groups = [1,2,4,5,6,7,8,9,10,11,12] it
726+ * implies that there are 2 groups of 4 threads each, where each group
727+ * of threads share L1, translation cache.
728+ *
729+ * The "ibm,ppc-interrupt-server#s" of the first group is {5,6,7,8}
730+ * and the "ibm,ppc-interrupt-server#s" of the second group is {9, 10,
731+ * 11, 12} structure
732+ *
733+ * Returns 0 on success, -EINVAL if the property does not exist,
734+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
735+ * property data isn't large enough.
736+ */
737+ static int parse_thread_groups (struct device_node * dn ,
738+ struct thread_groups * tg ,
739+ unsigned int property )
740+ {
741+ int i ;
742+ u32 thread_group_array [3 + MAX_THREAD_LIST_SIZE ];
743+ u32 * thread_list ;
744+ size_t total_threads ;
745+ int ret ;
746+
747+ ret = of_property_read_u32_array (dn , "ibm,thread-groups" ,
748+ thread_group_array , 3 );
749+ if (ret )
750+ return ret ;
751+
752+ tg -> property = thread_group_array [0 ];
753+ tg -> nr_groups = thread_group_array [1 ];
754+ tg -> threads_per_group = thread_group_array [2 ];
755+ if (tg -> property != property ||
756+ tg -> nr_groups < 1 ||
757+ tg -> threads_per_group < 1 )
758+ return - ENODATA ;
759+
760+ total_threads = tg -> nr_groups * tg -> threads_per_group ;
761+
762+ ret = of_property_read_u32_array (dn , "ibm,thread-groups" ,
763+ thread_group_array ,
764+ 3 + total_threads );
765+ if (ret )
766+ return ret ;
767+
768+ thread_list = & thread_group_array [3 ];
769+
770+ for (i = 0 ; i < total_threads ; i ++ )
771+ tg -> thread_list [i ] = thread_list [i ];
772+
773+ return 0 ;
774+ }
775+
776+ /*
777+ * get_cpu_thread_group_start : Searches the thread group in tg->thread_list
778+ * that @cpu belongs to.
779+ *
780+ * @cpu : The logical CPU whose thread group is being searched.
781+ * @tg : The thread-group structure of the CPU node which @cpu belongs
782+ * to.
783+ *
784+ * Returns the index to tg->thread_list that points to the the start
785+ * of the thread_group that @cpu belongs to.
786+ *
787+ * Returns -1 if cpu doesn't belong to any of the groups pointed to by
788+ * tg->thread_list.
789+ */
790+ static int get_cpu_thread_group_start (int cpu , struct thread_groups * tg )
791+ {
792+ int hw_cpu_id = get_hard_smp_processor_id (cpu );
793+ int i , j ;
794+
795+ for (i = 0 ; i < tg -> nr_groups ; i ++ ) {
796+ int group_start = i * tg -> threads_per_group ;
797+
798+ for (j = 0 ; j < tg -> threads_per_group ; j ++ ) {
799+ int idx = group_start + j ;
800+
801+ if (tg -> thread_list [idx ] == hw_cpu_id )
802+ return group_start ;
803+ }
804+ }
805+
806+ return -1 ;
807+ }
808+
809+ static int init_cpu_l1_cache_map (int cpu )
810+
811+ {
812+ struct device_node * dn = of_get_cpu_node (cpu , NULL );
813+ struct thread_groups tg = {.property = 0 ,
814+ .nr_groups = 0 ,
815+ .threads_per_group = 0 };
816+ int first_thread = cpu_first_thread_sibling (cpu );
817+ int i , cpu_group_start = -1 , err = 0 ;
818+
819+ if (!dn )
820+ return - ENODATA ;
821+
822+ err = parse_thread_groups (dn , & tg , THREAD_GROUP_SHARE_L1 );
823+ if (err )
824+ goto out ;
825+
826+ zalloc_cpumask_var_node (& per_cpu (cpu_l1_cache_map , cpu ),
827+ GFP_KERNEL ,
828+ cpu_to_node (cpu ));
829+
830+ cpu_group_start = get_cpu_thread_group_start (cpu , & tg );
831+
832+ if (unlikely (cpu_group_start == -1 )) {
833+ WARN_ON_ONCE (1 );
834+ err = - ENODATA ;
835+ goto out ;
836+ }
837+
838+ for (i = first_thread ; i < first_thread + threads_per_core ; i ++ ) {
839+ int i_group_start = get_cpu_thread_group_start (i , & tg );
840+
841+ if (unlikely (i_group_start == -1 )) {
842+ WARN_ON_ONCE (1 );
843+ err = - ENODATA ;
844+ goto out ;
845+ }
846+
847+ if (i_group_start == cpu_group_start )
848+ cpumask_set_cpu (i , per_cpu (cpu_l1_cache_map , cpu ));
849+ }
850+
851+ out :
852+ of_node_put (dn );
853+ return err ;
854+ }
855+
856+ static int init_big_cores (void )
857+ {
858+ int cpu ;
859+
860+ for_each_possible_cpu (cpu ) {
861+ int err = init_cpu_l1_cache_map (cpu );
862+
863+ if (err )
864+ return err ;
865+
866+ zalloc_cpumask_var_node (& per_cpu (cpu_smallcore_map , cpu ),
867+ GFP_KERNEL ,
868+ cpu_to_node (cpu ));
869+ }
870+
871+ has_big_cores = true;
872+ return 0 ;
873+ }
874+
678875void __init smp_prepare_cpus (unsigned int max_cpus )
679876{
680877 unsigned int cpu ;
@@ -713,6 +910,12 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
713910 cpumask_set_cpu (boot_cpuid , cpu_l2_cache_mask (boot_cpuid ));
714911 cpumask_set_cpu (boot_cpuid , cpu_core_mask (boot_cpuid ));
715912
913+ init_big_cores ();
914+ if (has_big_cores ) {
915+ cpumask_set_cpu (boot_cpuid ,
916+ cpu_smallcore_mask (boot_cpuid ));
917+ }
918+
716919 if (smp_ops && smp_ops -> probe )
717920 smp_ops -> probe ();
718921}
@@ -1003,10 +1206,28 @@ static void remove_cpu_from_masks(int cpu)
10031206 set_cpus_unrelated (cpu , i , cpu_core_mask );
10041207 set_cpus_unrelated (cpu , i , cpu_l2_cache_mask );
10051208 set_cpus_unrelated (cpu , i , cpu_sibling_mask );
1209+ if (has_big_cores )
1210+ set_cpus_unrelated (cpu , i , cpu_smallcore_mask );
10061211 }
10071212}
10081213#endif
10091214
1215+ static inline void add_cpu_to_smallcore_masks (int cpu )
1216+ {
1217+ struct cpumask * this_l1_cache_map = per_cpu (cpu_l1_cache_map , cpu );
1218+ int i , first_thread = cpu_first_thread_sibling (cpu );
1219+
1220+ if (!has_big_cores )
1221+ return ;
1222+
1223+ cpumask_set_cpu (cpu , cpu_smallcore_mask (cpu ));
1224+
1225+ for (i = first_thread ; i < first_thread + threads_per_core ; i ++ ) {
1226+ if (cpu_online (i ) && cpumask_test_cpu (i , this_l1_cache_map ))
1227+ set_cpus_related (i , cpu , cpu_smallcore_mask );
1228+ }
1229+ }
1230+
10101231static void add_cpu_to_masks (int cpu )
10111232{
10121233 int first_thread = cpu_first_thread_sibling (cpu );
@@ -1023,6 +1244,7 @@ static void add_cpu_to_masks(int cpu)
10231244 if (cpu_online (i ))
10241245 set_cpus_related (i , cpu , cpu_sibling_mask );
10251246
1247+ add_cpu_to_smallcore_masks (cpu );
10261248 /*
10271249 * Copy the thread sibling mask into the cache sibling mask
10281250 * and mark any CPUs that share an L2 with this CPU.
0 commit comments