Skip to content

Conversation

@felipepiovezan
Copy link

This NFC commit converts the helper function FindTaskId into FindTaskIds, operating on an array of task addresses instead of a single task address.

This will make the subsequent diff to use a vectorized memory read much smaller.

@felipepiovezan
Copy link
Author

@swift-ci test

@felipepiovezan
Copy link
Author

@swift-ci test macos platform

1 similar comment
@felipepiovezan
Copy link
Author

@swift-ci test macos platform

Comment on lines +196 to +226
/// Propagate input errors directly to the output, forward proper inputs to
/// `to_read`.
for (std::optional<addr_t> maybe_ptr : maybe_task_addrs) {
if (!maybe_ptr)
final_results.emplace_back(std::nullopt);
else {
final_results.push_back(0);
to_read.push_back(*maybe_ptr + job_id_offset);
}
}

/// TODO: replace this loop with a vectorized memory read.
llvm::SmallVector<std::optional<addr_t>> read_results;
for (addr_t task_id_addr : to_read) {
Status error;
// The Task ID is at offset job_id_offset from the Task pointer.
constexpr uint32_t num_bytes_task_id = 4;
auto task_id = process.ReadUnsignedIntegerFromMemory(
task_id_addr, num_bytes_task_id, LLDB_INVALID_ADDRESS, error);
if (error.Fail())
read_results.push_back(std::nullopt);
else
read_results.push_back(task_id);
}

// Move the results into the slots not filled by errors from the input.
llvm::ArrayRef<std::optional<addr_t>> results_ref = read_results;
for (std::optional<addr_t> &maybe_result : final_results)
if (maybe_result)
maybe_result = results_ref.consume_front();
assert(results_ref.empty());

Choose a reason for hiding this comment

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

Is the three for loops required for the future version using the multi memory read? As it is here, I see it as more complex than a single for loop, and don't see why it would be three.

Copy link
Author

Choose a reason for hiding this comment

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

The middle loop is going to be removed: felipepiovezan@41d4977

Copy link
Author

Choose a reason for hiding this comment

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

The two other loops are just supporting the fact that the inputs may be optional null, but the vectorized memory read cannot handle that, so we need to drop the nullopts and restore them later

Copy link
Author

Choose a reason for hiding this comment

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

I should emphasize: most of this PR is so that the diff linked above is minimal

// If this is not a thread running a Task, add it to the list as is.
if (!task_id) {
LLDB_LOG(log, "OperatingSystemSwiftTasks: could not get ID of Task {0:x}",
*task_addr);

Choose a reason for hiding this comment

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

is this deref of task_addr safe? it seems it could be nullopt here.

Copy link
Author

Choose a reason for hiding this comment

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

It is, if we had a task id, then we must have had a task addr (that's where we are reading from)

Copy link
Author

Choose a reason for hiding this comment

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

Oh sorry, my bad, I thought this was a comment on a different line

Copy link
Author

Choose a reason for hiding this comment

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

fixed it

…eads part 2

This NFC commit converts the helper function FindTaskId into
FindTaskIds, operating on an array of task addresses instead of a single
task address.

This will make the subsequent diff to use a vectorized memory read much
smaller.
@felipepiovezan felipepiovezan force-pushed the felipe/multimem_prep_swift_p2 branch from 67b4dc4 to fcab7f1 Compare October 23, 2025 17:04
@felipepiovezan
Copy link
Author

@swift-ci test

FindTaskIds(llvm::ArrayRef<std::optional<addr_t>> maybe_task_addrs,
Process &process) {
llvm::SmallVector<std::optional<uint64_t>> final_results;
llvm::SmallVector<addr_t> to_read;

Choose a reason for hiding this comment

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

If it's unlikely we hit the small case I would just use a vector here, but in leaf functions the SmallVector doesn't really hurt, so maybe you can ignore this :-)

@felipepiovezan
Copy link
Author

@swift-ci test windows platform

@felipepiovezan felipepiovezan merged commit 6528966 into swiftlang:stable/21.x Oct 24, 2025
3 checks passed
@felipepiovezan felipepiovezan deleted the felipe/multimem_prep_swift_p2 branch October 24, 2025 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants