Skip to content

GH-116422: Tier2 hot/cold splitting #116813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9a4879d
Subdivide uop instruction into deopt, exit and error targets
markshannon Mar 12, 2024
b6b6426
Pass length of trace around.
markshannon Mar 12, 2024
20a7afe
Hot cold splitting. Work in progress
markshannon Mar 12, 2024
801062d
Further progress on hot-cold- splitting
markshannon Mar 12, 2024
53b90bc
Change error exit code to fix length. All test passing for T2 interpr…
markshannon Mar 14, 2024
aecdfc2
Do not allow eval breaker and jumps in same T2 micro-op
markshannon Mar 14, 2024
d365f58
Add JIT support
markshannon Mar 14, 2024
814d0fc
Merge branch 'main' into tier2-hot-cold-splitting
markshannon Mar 14, 2024
97428fa
Revert unneeded change
markshannon Mar 14, 2024
3c2154f
Add missing return annotation
markshannon Mar 14, 2024
a74756d
Better formatting
markshannon Mar 14, 2024
817a590
Fix assert
markshannon Mar 14, 2024
197abba
Merge branch 'main' into tier2-hot-cold-splitting
markshannon Mar 14, 2024
9d0d03c
EXIT_IF does not implies DEOPT_IF
markshannon Mar 15, 2024
79ec8ef
Don't overflow the trace buffer
markshannon Mar 15, 2024
1dc1207
Merge branch 'main' into tier2-hot-cold-splitting
markshannon Mar 15, 2024
70b0ff5
Make sure COLD_EXIT has correct uop instruction format.
markshannon Mar 19, 2024
9cfa212
Merge branch 'main' into tier2-hot-cold-splitting
markshannon Mar 19, 2024
96941be
Merge branch 'main' into tier2-hot-cold-splitting
markshannon Mar 19, 2024
c19a18a
Remove NOPs before interpreting in T2.
markshannon Mar 19, 2024
7ab86e2
Rename _PyUop_Popped
markshannon Mar 20, 2024
fa5d14b
Address review comments
markshannon Mar 20, 2024
5217c12
Add comment
markshannon Mar 20, 2024
43ba205
Rename and move macros
markshannon Mar 20, 2024
3c4869b
Patch error jumps
markshannon Mar 20, 2024
b324933
Make assert a fatal error
markshannon Mar 20, 2024
71a2cae
Rename analyzer attributes for clarity
markshannon Mar 20, 2024
3f5dc4d
Remove redundant macros
markshannon Mar 20, 2024
6644e66
Merge branch 'main' into tier2-hot-cold-splitting
markshannon Mar 22, 2024
151db6a
Address code review
markshannon Mar 25, 2024
37627d3
Merge branch 'main' into tier2-hot-cold-splitting
markshannon Mar 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions Include/cpython/optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,63 @@ typedef struct {
PyCodeObject *code; // Weak (NULL if no corresponding ENTER_EXECUTOR).
} _PyVMData;

#define UOP_FORMAT_TARGET 0
#define UOP_FORMAT_EXIT 1
#define UOP_FORMAT_JUMP 2
#define UOP_FORMAT_UNUSED 3

/* Depending on the format,
* the 32 bits between the oparg and operand are:
* UOP_FORMAT_TARGET:
* uint32_t target;
* UOP_FORMAT_EXIT
* uint16_t exit_index;
* uint16_t error_target;
* UOP_FORMAT_JUMP
* uint16_t jump_target;
* uint16_t error_target;
*/
typedef struct {
uint16_t opcode;
uint16_t opcode:14;
uint16_t format:2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that format is a property of the oparg, not the instruction itself. It is never correct to execute an instruction with the wrong format for its oparg, so it feels wrong to provide it separately here and allow them to drift out of sync (which I just spent a lot of time debugging yesterday). Bonus points for not needing a bitfield.

Copy link
Member Author

@markshannon markshannon Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may never correct to execute an instruction with the wrong format, but this is primarily a format for optimization.
The "target" format is the correct format for all instructions during optimization.

If we care about tier 2 interpreter performance, we will want a different format for execution anyway.
What we could do is use different formats before and after prepare_for_execution, but I'd rather leave that for another PR.

What's wrong with bitfields?

uint16_t oparg;
union {
uint32_t target;
uint32_t exit_index;
struct {
union {
uint16_t exit_index;
uint16_t jump_target;
};
uint16_t error_target;
};
};
uint64_t operand; // A cache entry
} _PyUOpInstruction;

static inline uint32_t uop_get_target(const _PyUOpInstruction *inst)
{
assert(inst->format == UOP_FORMAT_TARGET);
return inst->target;
}

static inline uint16_t uop_get_exit_index(const _PyUOpInstruction *inst)
{
assert(inst->format == UOP_FORMAT_EXIT);
return inst->exit_index;
}

static inline uint16_t uop_get_jump_target(const _PyUOpInstruction *inst)
{
assert(inst->format == UOP_FORMAT_JUMP);
return inst->jump_target;
}

static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
{
assert(inst->format != UOP_FORMAT_TARGET);
return inst->error_target;
}

typedef struct _exit_data {
uint32_t target;
int16_t temperature;
Expand Down
116 changes: 57 additions & 59 deletions Include/internal/pycore_opcode_metadata.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Include/internal/pycore_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern "C" {
#include <stdbool.h>

// This is the length of the trace we project initially.
#define UOP_MAX_TRACE_LENGTH 512
#define UOP_MAX_TRACE_LENGTH 800

#define TRACE_STACK_SIZE 5

Expand Down
195 changes: 99 additions & 96 deletions Include/internal/pycore_uop_ids.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading