Page MenuHomeFreeBSD

nvme: Eliminate redundant code
ClosedPublic

Authored by imp on Aug 3 2023, 10:40 PM.
Tags
None
Referenced Files
F82735977: D41310.id.diff
Thu, May 2, 3:43 AM
F82735916: D41310.id125677.diff
Thu, May 2, 3:42 AM
F82735915: D41310.id125545.diff
Thu, May 2, 3:42 AM
F82718908: D41310.diff
Wed, May 1, 11:33 PM
Unknown Object (File)
Dec 20 2023, 6:06 AM
Unknown Object (File)
Sep 9 2023, 9:14 AM
Unknown Object (File)
Aug 17 2023, 1:42 PM
Unknown Object (File)
Aug 7 2023, 11:32 PM
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.