Repository navigation
AXI performance monitor driver - #2222
Conversation
pelwell
left a comment
There was a problem hiding this comment.
Device tree is supposed to describe the hardware, not specify a driver. I don't see any reason not call this bcm2835-axiperf, even though we wrote it.
I've hit my comments limit. Try running checkpatch and I'll have another go on the result.
| }, | ||
| }; | ||
|
|
||
| static int __init rpi_axiperf_init(void) |
| } | ||
|
|
||
| module_init(rpi_axiperf_init); | ||
| module_exit(rpi_axiperf_exit); |
There was a problem hiding this comment.
...to this one, inclusive, with:
module_platform_driver(rpi_axiperf_driver);
| // Now storage for the per monitor settings and the resulting | ||
| // performance figures | ||
| struct | ||
| { |
There was a problem hiding this comment.
Don't forget to stick to the ugly kernel brace placement rules.
| // Record results from the three Bus watchers per monitor and push to the sysfs | ||
|
|
||
| // General reg | ||
| const int GEN_CTRL = 0x00; |
There was a problem hiding this comment.
The kernel devs prefer #defines to const ints (go figure), but if you choose to stick with consts you'll have to change the symbols to lower case.
| int i; | ||
| void __iomem *addr = state->monitor[monitor].base_address | ||
| + watcher + BW_ATRANS_OFFSET; | ||
| for (i=0;i<NUM_BUS_WATCHER_RESULTS ;i++, addr+=4) |
There was a problem hiding this comment.
Spaces after semicolons here, none before.
| * spread our 3 actual monitors over them | ||
| */ | ||
| num_buses[monitor] = hweight32(state->monitor[monitor].bus_enabled); | ||
| num_buses[monitor] = min(num_buses[monitor], |
There was a problem hiding this comment.
The double assignment gave me a momentary WTF... It looks like the line is already over-long, so why not split it like this instead?
num_buses[monitor] = min(
hweight32(state->monitor[monitor].bus_enabled),
NUM_BUS_WATCHERS_PER_MONITOR);
There was a problem hiding this comment.
But see previous comment about a local pointer to state->monitor[monitor].
| // No, disable all monitoring for this monitor | ||
| set_monitor_control(monitor, GEN_CTL_RESET_BIT); | ||
| } else { | ||
| int i; |
There was a problem hiding this comment.
The indentation for this section is wrong. You've got enough logic in here that you might want to split out a helper function.
|
|
||
| for (monitor = 0; monitor < NUM_MONITORS; monitor++) { | ||
| // Anything enabled? | ||
| if (state->monitor[monitor].bus_enabled == 0) { |
There was a problem hiding this comment.
This loop is crying out for a local pointer to replace "state->monitor[monitor]".
| do { | ||
| state->monitor[monitor].last_monitored++; | ||
| state->monitor[monitor].last_monitored &= 0xf; //wrap around | ||
| } while ((state->monitor[monitor].bus_enabled & |
There was a problem hiding this comment.
Kernel devs prefer "!x" to "x == 0".
1da1327 to
e13a34c
Compare
e262255 to
1e16a53
Compare
e13a34c to
a855b93
Compare
|
I've pushed a much cleaned up version. Please be gentle. |
f4b3ddd to
ecbbac9
Compare
a855b93 to
5e93a76
Compare
firmware: New mailbox fns for peripheral access See: raspberrypi/linux#2222
firmware: New mailbox fns for peripheral access See: raspberrypi/linux#2222
fec87ed to
b76f96e
Compare
5e93a76 to
e9ea6dc
Compare
|
@popcornmix @pelwell @6by9 I have updated to latest tree so this can now be merged if it is regarded as OK. COuld probably still do with some good 'ole revoooing. |
e9ea6dc to
8296317
Compare
|
|
||
| /* Two monitors, System and VPU, each with the following register sets | ||
| * Each monitor can only monitor one bus at a time, so we time share them, | ||
| * giving each bus 100ms (default, settable via debufs) of time on its |
|
|
||
| #include <linux/device.h> | ||
| #include <linux/debugfs.h> | ||
| #include <linux/netdevice.h> |
There was a problem hiding this comment.
Upstream would whinge about alphabetical order.
|
|
||
| struct rpi_firmware *firmware; | ||
|
|
||
| // Sample time spent on for each bus |
There was a problem hiding this comment.
Phil: Are we being fussy about /* */ commenting over C99 // ?
There was a problem hiding this comment.
I'm not fussed provided checkpatch is happy.
There was a problem hiding this comment.
I'll change them all anyway.
There was a problem hiding this comment.
Am I not looking at the latest, or are we ignoring them (somehow checkpatch is letting that through).
Ah, I have --strict --codespell set as arguments to checkpatch by default (although that is still allowing C99 commenting!)
| * raspberrypi_axi_monitor.c | ||
| * | ||
| * Created on: 26 Sep 2017 | ||
| * Author: jamesh |
|
|
||
| static struct rpi_axiperf *state; | ||
|
|
||
| /* Two monitors, System and VPU, each with the following register sets |
There was a problem hiding this comment.
Fullstop on the end of the line.
Upstream typically want:
/*
* Comments here
*/
for multi line comments.
| // general registers | ||
| const int GEN_CTRL; | ||
|
|
||
| const int GEN_CTL_ENABLE_BIT = 0x01; |
There was a problem hiding this comment.
Use the BIT(x) macros throughout?
GENMASK(<top_bit>, <bottom_bit>) for masks.
| const int BW_CTRL_BUS_WATCH_MASK = 0x3d << 0; // 6 bits | ||
| const int BW_CTRL_BUS_FILTER_SHIFT = 8; | ||
|
|
||
| static char *bus_filter_strings[] = { |
There was a problem hiding this comment.
const for all these arrays and sizes?
| if (kthread_should_stop()) | ||
| return 0; | ||
|
|
||
| msleep(100); |
There was a problem hiding this comment.
Comments said default was 100ms settable in debugfs, or is this a different delay?
There was a problem hiding this comment.
OOOh, bug, that shouldn't be there I don't think.
| return PTR_ERR(state->monitor[i].base_address); | ||
|
|
||
| // Enable all buses by default | ||
| state->monitor[i].bus_enabled = 0xffff; |
There was a problem hiding this comment.
All enabled by default, and driver enabled in DT. Is that the desired default? Does it have any real overhead?
There was a problem hiding this comment.
Intention is for this module only to be built in if specifically requested for debugging purposes, overhead in the not built case is clearly 0, but there is overhead when it is installed and running.
There was a problem hiding this comment.
In which case shouldn't the default status in DT be "disabled"? It's currently "okay" in bcm270x.dtsi.
(Or have it in the build but disabled in DT by default? Still zero overhead for most, but easier to enable when desired).
| .probe = rpi_axiperf_probe, | ||
| .remove = rpi_axiperf_remove, | ||
| .driver = { | ||
| .name = "bcm2835-axiperf", |
There was a problem hiding this comment.
Same discussion as with the GPIO expander driver. This isn't generic for the BCM283x chips as it relies on the firmware.
"raspberrypi,axiperf" instead? (It is meant to be "vendor,driver", and you had no vendor)
There was a problem hiding this comment.
We haven't always followed the principle, but device tree is supposed to describe the hardware, not the driver. The performance monitors are Broadcom parts, even if the driver is pi-specific.
There was a problem hiding this comment.
So, change the function names to bcm-blah-blah instead of rpi-blah-blah as well as the driver name?
There was a problem hiding this comment.
No, I'm agreeing with you. I think the DT compatible string should remain "bcm2835,axiperf", and I'm happy with the downstream "rpi" function names. I'd go further and change the driver name to include "rpi" or "raspberrypi".
There was a problem hiding this comment.
I'll defer to Phil on this, but the usage is a hybrid where half of it is talking to the firmware (compatible string "raspberrypi,bcm2835-firmware") and not directly to the hardware.
| static ssize_t mywriter(struct file *fp, const char __user *user_buffer, | ||
| size_t count, loff_t *position) | ||
| { | ||
| // TODO: this really needs to zero the registers, not this stuff. |
There was a problem hiding this comment.
Are you going to implement this?
There was a problem hiding this comment.
Will remove the comment - its not really necessary. I'd like to leave the function so it can be used at a later date although I suspect upstream wouldn't like that.
| .probe = rpi_axiperf_probe, | ||
| .remove = rpi_axiperf_remove, | ||
| .driver = { | ||
| .name = "bcm2835-axiperf", |
There was a problem hiding this comment.
We haven't always followed the principle, but device tree is supposed to describe the hardware, not the driver. The performance monitors are Broadcom parts, even if the driver is pi-specific.
|
|
||
| // Special case for the VPU monitor, we must use the mailbox interface | ||
| // as it is not accessible from the ARM address space. | ||
| state->monitor[VPU_MONITOR].use_mailbox_interface = 1; |
There was a problem hiding this comment.
Sorry, an extra one.
This is a nasty dependency between driver and DT that the addresses for the VPU_MONITOR must be second in the DT list of regs. Is there a better way of reflecting that?
You've also hard coded the address as 0x7ee08000 at line 551, so the DT value doesn't actually matter.
There was a problem hiding this comment.
It's hardcoded, because the values I was getting back were not the ones I had in the DT entry, and I never figured out why. Probably should look at that but not got too much time for polishing.
There was a problem hiding this comment.
There are precedents for defining an order for items under reg. The alternative is to have a reg-names property containing an array of names, and use platform_get_resource_byname().
The reason the address has changed is that the bus address has been converted into an ARM address. You can retrieve the original value using of_get_property_read_u32_index() or of_get_property_read_u32_array().
|
Ah ha, as Alan Partridge would say. Will fix that up.
…On 2 Nov 2017 16:04, "Phil Elwell" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In drivers/perf/raspberrypi_axi_monitor.c
<#2222 (comment)>:
> + return -ENOMEM;
+
+ /* Get the firmware handle for future rpi-firmware-xxx calls */
+ fw_node = of_parse_phandle(np, "firmware", 0);
+ if (!fw_node) {
+ dev_err(dev, "Missing firmware node\n");
+ return -ENOENT;
+ }
+
+ state->firmware = rpi_firmware_get(fw_node);
+ if (!state->firmware)
+ return -EPROBE_DEFER;
+
+ // Special case for the VPU monitor, we must use the mailbox interface
+ // as it is not accessible from the ARM address space.
+ state->monitor[VPU_MONITOR].use_mailbox_interface = 1;
There are precedents for defining an order for items under reg. The
alternative is to have a reg-names property containing an array of names,
and use platform_get_resource_byname().
The reason the address has changed is that the bus address has been
converted into an ARM address. You can retrieve the original value using
of_get_property_read_u32_index() or of_get_property_read_u32_array().
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2222 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADqrHVYDnjWSxeKOTP8ga9zIQpagBJlmks5syegXgaJpZM4P1q72>
.
|
b76f96e to
59341bd
Compare
2e52aff to
d7c8487
Compare
| /* | ||
| * raspberrypi_axi_monitor.c | ||
| * | ||
| * Created on: 26 Sep 2017 |
There was a problem hiding this comment.
Odd line to have in the header.
There was a problem hiding this comment.
Ah, added by Eclipse when I created the file. Can remove.
|
|
||
| struct rpi_firmware *firmware; | ||
|
|
||
| // Sample time spent on for each bus |
There was a problem hiding this comment.
Am I not looking at the latest, or are we ignoring them (somehow checkpatch is letting that through).
Ah, I have --strict --codespell set as arguments to checkpatch by default (although that is still allowing C99 commenting!)
| reg = <0x7e009800 0x100>, | ||
| <0x7ee08000 0x100>; | ||
| firmware = <&firmware>; | ||
| status = "okay"; |
There was a problem hiding this comment.
@pelwell Are you happy for this to be enabled by default even though the driver won't be built?
There was a problem hiding this comment.
I think I'd rather have it disabled at this level then enabled higher up, e.g. by bcm2708-rpi.dtsi (even though the two are equivalent).
In general it seems to be frowned on to introduce nodes with an explicit status of "okay", since that is the default.
There was a problem hiding this comment.
I have no idea what to put here, I copied that section from another section, so do not know what the status parameter actually means.
d7c8487 to
a2af72c
Compare
| state->firmware = rpi_firmware_get(fw_node); | ||
| if (!state->firmware) | ||
| { | ||
| dev_err(dev, "Probe deferred\n"); |
There was a problem hiding this comment.
dev_err is a touch high for a probe deferral.
There was a problem hiding this comment.
Sorry, see previous comment.
|
|
||
| const static char *monitor_name[] = { | ||
| "System Monitor", | ||
| "VPU Monitor" |
There was a problem hiding this comment.
These are also the directory names and they have spaces in :-(
We know these are going to be monitoring things, so is the word "monitor" really required in either case?
There was a problem hiding this comment.
Bugger, put those in this morning for debugging, forgot to take them out. Inclined to remove both.
There was a problem hiding this comment.
Oop, wrong comment. I'll remove spaces, been meaning to for ages anyway...
a2af72c to
7d11e59
Compare
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI bus performance monitors. Requires the new mailbox peripheral access for access to the VPU performance registers, system bus access is done using direct register reads. Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
Uses the debugfs I/F to provide access to the AXI
bus performance monitors.
Requires the new mailbox peripheral access for access
to the VPU performance registers, system bus access
is done using direct register reads.