Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] accel/amd-ai-engine: aiemlv2_set_part_clocks() clobbers tiles_inuse bitmap - [Low] accel/amd-ai-engine: % 2 discards mask bit 1 in aiemlv2_scan_part_clocks() --
commit 31b6ed2773ef86bbc6d6e5049ee938eccc623dd5 Author: Gregory Williams <[email protected]> accel/amd-ai-engine: Add support to enable/disable tile clocks This commit adds partition clock scanning and tile clock enable/disable operations for requesting and releasing AI Engine tiles. > diff --git a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c > b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c > index 0c9c7ccdd54e0..26dd1d726bfad 100644 > --- a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c > +++ b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c > @@ -13,6 +13,16 @@ > #define AIEMLV2_COL_SHIFT 25U > #define AIEMLV2_ROW_SHIFT 20U > > +/* > + * Register offsets > + */ > +#define AIEMLV2_SHIMPL_COLCLOCK_CTRL_REGOFF 0x0007FF20U > + > +/* > + * Register masks > + */ > +#define AIEMLV2_SHIMPL_COLCLOCK_CTRL_MASK GENMASK(1, 0) > + > static u32 aiemlv2_get_tile_type(struct aie_device *adev, struct > aie_location *loc) > { > u8 num_mem_rows = adev->ttype_attr[AIE_TILE_TYPE_MEMORY].num_rows; > @@ -25,8 +35,148 @@ static u32 aiemlv2_get_tile_type(struct aie_device *adev, > struct aie_location *l > return AIE_TILE_TYPE_SHIMNOC; > } > > +static int aiemlv2_scan_part_clocks(struct aie_partition *apart) > +{ > + struct aie_range *range = &apart->range; > + struct aie_device *adev = apart->adev; > + struct aie_location loc; > + > + /* Clear the bitmap of cores and memories clock state */ > + aie_resource_put_region(&apart->cores_clk_state, 0, > + apart->cores_clk_state.total); > + > + /* > + * If the clock buffer on shim tile is enabled, then all tiles above in > + * the same column are also enabled. > + */ > + > + loc.row = 0; > + for (loc.col = range->start.col; > + loc.col < range->start.col + range->size.col; > + loc.col++) { > + void __iomem *va; > + u32 val, nbitpos; > + > + nbitpos = (loc.col - range->start.col) * (range->size.row - 1) > + loc.row; > + > + va = adev->base + > + aie_cal_regoff(adev, loc, > + AIEMLV2_SHIMPL_COLCLOCK_CTRL_REGOFF); > + val = readl(va); > + > + if (!((val & AIEMLV2_SHIMPL_COLCLOCK_CTRL_MASK) % 2)) > + continue; [Severity: Low] Does applying "% 2" after masking with AIEMLV2_SHIMPL_COLCLOCK_CTRL_MASK (GENMASK(1, 0)) unintentionally discard bit 1? Since (val & 0x3) % 2 only tests bit 0, a column with bit 1 set and bit 0 clear will be treated as clocked off during aie_part_create() -> aie_part_scan_clk_state(). > + > + aie_resource_set(&apart->cores_clk_state, nbitpos, > + range->size.row - 1); > + } > + /* > + * Set the tiles in use bitmap. > + * In case of scanning, tiles which are powered on are considered as > + * tiles in use. > + */ > + bitmap_copy(apart->tiles_inuse.bitmap, apart->cores_clk_state.bitmap, > + apart->tiles_inuse.total); > + > + return 0; > +} > + > +static int aiemlv2_set_part_clocks(struct aie_partition *apart) > +{ > + struct aie_range *range = &apart->range; > + struct aie_range prev_range = {}; > + struct aie_location loc; > + int ret = -EINVAL; > + u32 prev_ops = 0; > + > + for (loc.col = 0; loc.col < range->size.col; loc.col++) { > + u32 startbit, col_inuse = 0; > + > + startbit = loc.col * (range->size.row - 1); > + > + for (loc.row = range->start.row + 1; > + loc.row < range->start.row + range->size.row; > + loc.row++) { > + u32 nbitpos = startbit + loc.row - 1; > + > + if (aie_resource_testbit(&apart->tiles_inuse, nbitpos)) > { > + col_inuse = 1; > + break; > + } > + } > + > + if (col_inuse) { > + struct aie_range op_range = { > + .start.col = loc.col + range->start.col, > + .size.col = 1, > + }; > + > + ret = aie_resource_set(&apart->tiles_inuse, startbit, > + apart->range.size.row - 1); > + if (ret) > + return ret; > + ret = aie_resource_set(&apart->cores_clk_state, > startbit, > + apart->range.size.row - 1); [Severity: Medium] Should aiemlv2_set_part_clocks() avoid setting the entire column in apart->tiles_inuse when col_inuse is true? When aie_part_request_tiles() requests a subset of tiles in a column, it sets only those tile bits in apart->tiles_inuse, but this call marks every row in the column as in use. If the caller later releases the requested tiles via aie_part_release_tiles(), only the specified tile bits are cleared in apart->tiles_inuse, so aiemlv2_set_part_clocks() sees the remaining row bits still set, re-sets the released bits in apart->tiles_inuse, and never disables the column clock buffer. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=14
