@@ -663,9 +663,12 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)
663663 */
664664static void mbm_bw_count (u32 closid , u32 rmid , struct rmid_read * rr )
665665{
666- u32 idx = resctrl_arch_rmid_idx_encode (closid , rmid );
667- struct mbm_state * m = & rr -> d -> mbm_local [idx ];
668666 u64 cur_bw , bytes , cur_bytes ;
667+ struct mbm_state * m ;
668+
669+ m = get_mbm_state (rr -> d , closid , rmid , rr -> evtid );
670+ if (WARN_ON_ONCE (!m ))
671+ return ;
669672
670673 cur_bytes = rr -> val ;
671674 bytes = cur_bytes - m -> prev_bw_bytes ;
@@ -752,20 +755,20 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *dom_mbm)
752755 u32 closid , rmid , cur_msr_val , new_msr_val ;
753756 struct mbm_state * pmbm_data , * cmbm_data ;
754757 struct rdt_ctrl_domain * dom_mba ;
758+ enum resctrl_event_id evt_id ;
755759 struct rdt_resource * r_mba ;
756- u32 cur_bw , user_bw , idx ;
757760 struct list_head * head ;
758761 struct rdtgroup * entry ;
759-
760- if (!is_mbm_local_enabled ())
761- return ;
762+ u32 cur_bw , user_bw ;
762763
763764 r_mba = & rdt_resources_all [RDT_RESOURCE_MBA ].r_resctrl ;
765+ evt_id = rgrp -> mba_mbps_event ;
764766
765767 closid = rgrp -> closid ;
766768 rmid = rgrp -> mon .rmid ;
767- idx = resctrl_arch_rmid_idx_encode (closid , rmid );
768- pmbm_data = & dom_mbm -> mbm_local [idx ];
769+ pmbm_data = get_mbm_state (dom_mbm , closid , rmid , evt_id );
770+ if (WARN_ON_ONCE (!pmbm_data ))
771+ return ;
769772
770773 dom_mba = get_ctrl_domain_from_cpu (smp_processor_id (), r_mba );
771774 if (!dom_mba ) {
@@ -784,7 +787,9 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *dom_mbm)
784787 */
785788 head = & rgrp -> mon .crdtgrp_list ;
786789 list_for_each_entry (entry , head , mon .crdtgrp_list ) {
787- cmbm_data = & dom_mbm -> mbm_local [entry -> mon .rmid ];
790+ cmbm_data = get_mbm_state (dom_mbm , entry -> closid , entry -> mon .rmid , evt_id );
791+ if (WARN_ON_ONCE (!cmbm_data ))
792+ return ;
788793 cur_bw += cmbm_data -> prev_bw ;
789794 }
790795
@@ -813,54 +818,45 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *dom_mbm)
813818 resctrl_arch_update_one (r_mba , dom_mba , closid , CDP_NONE , new_msr_val );
814819}
815820
816- static void mbm_update (struct rdt_resource * r , struct rdt_mon_domain * d ,
817- u32 closid , u32 rmid )
821+ static void mbm_update_one_event (struct rdt_resource * r , struct rdt_mon_domain * d ,
822+ u32 closid , u32 rmid , enum resctrl_event_id evtid )
818823{
819824 struct rmid_read rr = {0 };
820825
821826 rr .r = r ;
822827 rr .d = d ;
828+ rr .evtid = evtid ;
829+ rr .arch_mon_ctx = resctrl_arch_mon_ctx_alloc (rr .r , rr .evtid );
830+ if (IS_ERR (rr .arch_mon_ctx )) {
831+ pr_warn_ratelimited ("Failed to allocate monitor context: %ld" ,
832+ PTR_ERR (rr .arch_mon_ctx ));
833+ return ;
834+ }
835+
836+ __mon_event_count (closid , rmid , & rr );
823837
824838 /*
825- * This is protected from concurrent reads from user
826- * as both the user and we hold the global mutex .
839+ * If the software controller is enabled, compute the
840+ * bandwidth for this event id .
827841 */
828- if (is_mbm_total_enabled ()) {
829- rr .evtid = QOS_L3_MBM_TOTAL_EVENT_ID ;
830- rr .val = 0 ;
831- rr .arch_mon_ctx = resctrl_arch_mon_ctx_alloc (rr .r , rr .evtid );
832- if (IS_ERR (rr .arch_mon_ctx )) {
833- pr_warn_ratelimited ("Failed to allocate monitor context: %ld" ,
834- PTR_ERR (rr .arch_mon_ctx ));
835- return ;
836- }
837-
838- __mon_event_count (closid , rmid , & rr );
842+ if (is_mba_sc (NULL ))
843+ mbm_bw_count (closid , rmid , & rr );
839844
840- resctrl_arch_mon_ctx_free (rr .r , rr .evtid , rr .arch_mon_ctx );
841- }
842- if (is_mbm_local_enabled ()) {
843- rr .evtid = QOS_L3_MBM_LOCAL_EVENT_ID ;
844- rr .val = 0 ;
845- rr .arch_mon_ctx = resctrl_arch_mon_ctx_alloc (rr .r , rr .evtid );
846- if (IS_ERR (rr .arch_mon_ctx )) {
847- pr_warn_ratelimited ("Failed to allocate monitor context: %ld" ,
848- PTR_ERR (rr .arch_mon_ctx ));
849- return ;
850- }
851-
852- __mon_event_count (closid , rmid , & rr );
845+ resctrl_arch_mon_ctx_free (rr .r , rr .evtid , rr .arch_mon_ctx );
846+ }
853847
854- /*
855- * Call the MBA software controller only for the
856- * control groups and when user has enabled
857- * the software controller explicitly.
858- */
859- if (is_mba_sc (NULL ))
860- mbm_bw_count (closid , rmid , & rr );
848+ static void mbm_update (struct rdt_resource * r , struct rdt_mon_domain * d ,
849+ u32 closid , u32 rmid )
850+ {
851+ /*
852+ * This is protected from concurrent reads from user as both
853+ * the user and overflow handler hold the global mutex.
854+ */
855+ if (is_mbm_total_enabled ())
856+ mbm_update_one_event (r , d , closid , rmid , QOS_L3_MBM_TOTAL_EVENT_ID );
861857
862- resctrl_arch_mon_ctx_free ( rr . r , rr . evtid , rr . arch_mon_ctx );
863- }
858+ if ( is_mbm_local_enabled ())
859+ mbm_update_one_event ( r , d , closid , rmid , QOS_L3_MBM_LOCAL_EVENT_ID );
864860}
865861
866862/*
@@ -1224,11 +1220,13 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
12241220
12251221 if (rdt_cpu_has (X86_FEATURE_CQM_MBM_TOTAL )) {
12261222 mbm_total_event .configurable = true;
1227- mbm_config_rftype_init ("mbm_total_bytes_config" );
1223+ resctrl_file_fflags_init ("mbm_total_bytes_config" ,
1224+ RFTYPE_MON_INFO | RFTYPE_RES_CACHE );
12281225 }
12291226 if (rdt_cpu_has (X86_FEATURE_CQM_MBM_LOCAL )) {
12301227 mbm_local_event .configurable = true;
1231- mbm_config_rftype_init ("mbm_local_bytes_config" );
1228+ resctrl_file_fflags_init ("mbm_local_bytes_config" ,
1229+ RFTYPE_MON_INFO | RFTYPE_RES_CACHE );
12321230 }
12331231 }
12341232
0 commit comments