Skip to content

Commit f700225

Browse files
committed
kernel_if: reduce scope of variables
Declare `segment` as `unsigned int` to avoid unnecessary type punning. Keep zeroing upper bits since `unsigned int` may be larger than 32 bits.
1 parent 53d8136 commit f700225

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

src/acl_kernel_if.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,17 +1288,8 @@ void acl_kernel_if_launch_kernel(acl_kernel_if *kern,
12881288
// Called when we receive a kernel status interrupt. Cycle through all of
12891289
// the running accelerators and check for updated status.
12901290
void acl_kernel_if_update_status(acl_kernel_if *kern) {
1291-
unsigned int k, i;
1292-
unsigned int csr;
1293-
int activation_id;
1294-
unsigned int printf_size;
1295-
uintptr_t segment, segment_pre_irq;
12961291
acl_assert_locked_or_sig();
12971292

1298-
#ifdef TEST_PROFILING_HARDWARE
1299-
uint64_t data[10];
1300-
#endif
1301-
13021293
#ifdef POLLING
13031294
ACL_KERNEL_IF_DEBUG_MSG_VERBOSE(kern, 10, ":: Updating kernel status.\n");
13041295
#else
@@ -1308,15 +1299,17 @@ void acl_kernel_if_update_status(acl_kernel_if *kern) {
13081299
// Get the state of kernel_cra address span extender segment prior to IRQ in
13091300
// hardware If IRQ is received in middle of segment change, segment value in
13101301
// cache and hardware could go out of sync
1311-
acl_kernel_if_read_32b(kern, OFFSET_KERNEL_CRA_SEGMENT,
1312-
(unsigned int *)&segment);
1302+
{
1303+
unsigned int segment;
1304+
acl_kernel_if_read_32b(kern, OFFSET_KERNEL_CRA_SEGMENT, &segment);
13131305

1314-
// Zero upper 32-bits on 64-bit machines
1315-
kern->cur_segment = segment & 0xffffffff;
1316-
segment_pre_irq = kern->cur_segment;
1306+
// Zero upper 32-bits on 64-bit machines
1307+
kern->cur_segment = segment & 0xffffffff;
1308+
}
1309+
const uintptr_t segment_pre_irq = kern->cur_segment;
13171310

13181311
// Check which accelerators are done and update their status appropriately
1319-
for (k = 0; k < kern->num_accel; ++k) {
1312+
for (unsigned int k = 0; k < kern->num_accel; ++k) {
13201313
int next_queue_back;
13211314
unsigned int finish_counter = 0;
13221315

@@ -1335,7 +1328,7 @@ void acl_kernel_if_update_status(acl_kernel_if *kern) {
13351328
}
13361329

13371330
// Read the accelerator's status register
1338-
csr = 0;
1331+
unsigned int csr = 0;
13391332
acl_kernel_cra_read(kern, k, KERNEL_OFFSET_CSR, &csr);
13401333

13411334
// Ignore non-status bits.
@@ -1370,11 +1363,11 @@ void acl_kernel_if_update_status(acl_kernel_if *kern) {
13701363
ACL_KERNEL_READ_BIT(csr, KERNEL_CSR_PROFILE_TEMPORAL_STATUS) == 0)
13711364
continue;
13721365

1373-
activation_id = kern->accel_job_ids[k][next_queue_back];
1366+
int activation_id = kern->accel_job_ids[k][next_queue_back];
13741367

13751368
// read the printf buffer size from the kernel cra, just after the
13761369
// kernel arguments
1377-
printf_size = 0;
1370+
unsigned int printf_size = 0;
13781371
if (kern->accel_num_printfs[k] > 0) {
13791372
acl_kernel_cra_read(kern, k, KERNEL_OFFSET_PRINTF_BUFFER_SIZE,
13801373
&printf_size);
@@ -1451,7 +1444,7 @@ void acl_kernel_if_update_status(acl_kernel_if *kern) {
14511444
finish_counter);
14521445
}
14531446

1454-
for (i = 0; i < finish_counter; i++) {
1447+
for (unsigned int i = 0; i < finish_counter; i++) {
14551448
activation_id = kern->accel_job_ids[k][next_queue_back];
14561449

14571450
// Tell the host library this job is done
@@ -1463,6 +1456,8 @@ void acl_kernel_if_update_status(acl_kernel_if *kern) {
14631456
ACL_KERNEL_IF_DEBUG_MSG(
14641457
kern, ":: testing profile hardware on accel_id=%u.\n", k);
14651458

1459+
uint64_t data[10];
1460+
14661461
acl_hal_mmd_get_profile_data(kern->physical_device_id, k, data, 6);
14671462

14681463
acl_hal_mmd_reset_profile_counters(kern->physical_device_id, k);

0 commit comments

Comments
 (0)