Page MenuHomeFreeBSD

nvme: Eliminate redundant code
ClosedPublic

Authored by imp on Aug 3 2023, 10:40 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Oct 26, 2:54 AM
Unknown Object (File)
Oct 4 2024, 1:57 AM
Unknown Object (File)
Oct 2 2024, 10:35 PM
Unknown Object (File)
Oct 2 2024, 10:30 PM
Unknown Object (File)
Oct 2 2024, 8:44 PM
Unknown Object (File)
Sep 21 2024, 9:51 PM
Unknown Object (File)
Jun 15 2024, 10:53 PM
Unknown Object (File)
Jun 14 2024, 5:55 AM
Subscribers

Details

Summary

get_admin_opcode_string and get_io_opcode_string are identical, but
start with different tables. Use a helper routine that takes an
argument to implement these instead.

Sponsored by: Netflix

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

imp requested review of this revision.Aug 3 2023, 10:40 PM
This revision is now accepted and ready to land.Aug 3 2023, 11:06 PM

Aren't opcodes just 8 bits anyway? Seems like you could make these tables be indexed by the opcode and always have 256 entries with a fallback if the entry is NULL and avoid the loop. Granted, it's likely not a critical path anyway, but still:

#define OPC_ENTRY(opc) \
    [(opc)] = __STRING(opc)

static const char *admin_opcodes[256] = {
    OPC_ENTRY(NVME_OPC_ABORT),
    ....
};

static const char *
get_opcode_string(const char **table, const char *default, uint8_t opc)
{
    const char *s;

    s = table[opc];
    return (s == NULL ? default : s);
}

static const char *
get_admin_opcode_string(uint8_t opc)
{
    return (get_opcode_string(admin_opcode, "ADMIN COMMAND", opc));
}

I like @jhb 's table approach but would prefer the shorter string (i.e., RESERVATION REGISTER vs NVME_OPC_RESERVATION_REGISTER

ok. trying jhb's suggstion on this commit breaks future commits, so that's a non-starter (at least more work than I think is worth)
However, doing it at the end of the process is easy, so https://reviews.freebsd.org/D41353
does the deed.

This revision was automatically updated to reflect the committed changes.