@@ -1243,6 +1243,21 @@ static void __get_engine_usage_record(struct intel_engine_cs *engine,
1243
1243
} while (++ i < 6 );
1244
1244
}
1245
1245
1246
+ static void __set_engine_usage_record (struct intel_engine_cs * engine ,
1247
+ u32 last_in , u32 id , u32 total )
1248
+ {
1249
+ struct iosys_map rec_map = intel_guc_engine_usage_record_map (engine );
1250
+
1251
+ #define record_write (map_ , field_ , val_ ) \
1252
+ iosys_map_wr_field(map_, 0, struct guc_engine_usage_record, field_, val_)
1253
+
1254
+ record_write (& rec_map , last_switch_in_stamp , last_in );
1255
+ record_write (& rec_map , current_context_index , id );
1256
+ record_write (& rec_map , total_runtime , total );
1257
+
1258
+ #undef record_write
1259
+ }
1260
+
1246
1261
static void guc_update_engine_gt_clks (struct intel_engine_cs * engine )
1247
1262
{
1248
1263
struct intel_engine_guc_stats * stats = & engine -> stats .guc ;
@@ -1363,9 +1378,12 @@ static ktime_t guc_engine_busyness(struct intel_engine_cs *engine, ktime_t *now)
1363
1378
total += intel_gt_clock_interval_to_ns (gt , clk );
1364
1379
}
1365
1380
1381
+ if (total > stats -> total )
1382
+ stats -> total = total ;
1383
+
1366
1384
spin_unlock_irqrestore (& guc -> timestamp .lock , flags );
1367
1385
1368
- return ns_to_ktime (total );
1386
+ return ns_to_ktime (stats -> total );
1369
1387
}
1370
1388
1371
1389
static void guc_enable_busyness_worker (struct intel_guc * guc )
@@ -1431,8 +1449,21 @@ static void __reset_guc_busyness_stats(struct intel_guc *guc)
1431
1449
1432
1450
guc_update_pm_timestamp (guc , & unused );
1433
1451
for_each_engine (engine , gt , id ) {
1452
+ struct intel_engine_guc_stats * stats = & engine -> stats .guc ;
1453
+
1434
1454
guc_update_engine_gt_clks (engine );
1435
- engine -> stats .guc .prev_total = 0 ;
1455
+
1456
+ /*
1457
+ * If resetting a running context, accumulate the active
1458
+ * time as well since there will be no context switch.
1459
+ */
1460
+ if (stats -> running ) {
1461
+ u64 clk = guc -> timestamp .gt_stamp - stats -> start_gt_clk ;
1462
+
1463
+ stats -> total_gt_clks += clk ;
1464
+ }
1465
+ stats -> prev_total = 0 ;
1466
+ stats -> running = 0 ;
1436
1467
}
1437
1468
1438
1469
spin_unlock_irqrestore (& guc -> timestamp .lock , flags );
@@ -1543,13 +1574,19 @@ static void guc_timestamp_ping(struct work_struct *wrk)
1543
1574
1544
1575
static int guc_action_enable_usage_stats (struct intel_guc * guc )
1545
1576
{
1577
+ struct intel_gt * gt = guc_to_gt (guc );
1578
+ struct intel_engine_cs * engine ;
1579
+ enum intel_engine_id id ;
1546
1580
u32 offset = intel_guc_engine_usage_offset (guc );
1547
1581
u32 action [] = {
1548
1582
INTEL_GUC_ACTION_SET_ENG_UTIL_BUFF ,
1549
1583
offset ,
1550
1584
0 ,
1551
1585
};
1552
1586
1587
+ for_each_engine (engine , gt , id )
1588
+ __set_engine_usage_record (engine , 0 , 0xffffffff , 0 );
1589
+
1553
1590
return intel_guc_send (guc , action , ARRAY_SIZE (action ));
1554
1591
}
1555
1592
0 commit comments