8000 Refactor ASIC Initialization, Frequency Management, and Remove Global State by KillerInk · Pull Request #1146 · bitaxeorg/ESP-Miner · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor ASIC Initialization, Frequency Management, and Remove Global State #1146

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

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

KillerInk
Copy link
Contributor
@KillerInk KillerInk commented Jul 11, 2025

This PR refactors the ASIC initialization and frequency management code, and removes reliance on the GlobalState structure to improve readability, maintainability, and functionality.

Key changes include:

Function Consolidation: Merged redundant functions and improved function organization.
Global State Removal:
Removed the GlobalState parameter from most functions, simplifying function signatures.
Extracted relevant data directly where needed instead of relying on a global state.
These changes aim to streamline the ASIC management code while ensuring all ASIC types are properly supported and making the codebase more modular.

Copy link
github-actions bot commented Jul 11, 2025

Test Results

20 tests  ±0   20 ✅ ±0   0s ⏱️ ±0s
 1 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit e097540. ± Comparison against base commit 02a8bcf.

♻️ This comment has been updated with latest results.

Copy link
Collaborator
@johnny9 johnny9 left a comment

Choose a reason for hiding this comment

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

NACK

This doesn't address the issue with the dependancies between these components and main and in fact just makes a lot of this harder to eventually test.

What needs to be done is asic.h, for instance, needs to no longer know about global state.

On top of that this is far too large of a change to go in without any additional tests being written.

@KillerInk
Copy link
Contributor Author

NACK

This doesn't address the issue with the dependancies between these components and main and in fact just makes a lot of this harder to eventually test.

What needs to be done is asic.h, for instance, needs to no longer know about global state.

On top of that this is far too large of a change to go in without any additional tests being written.

the thing is that the GLOBAL_STATE is static in main but not accessible without routing it through methods, in fact its static^^
other thing is that everything that is stored in that pointer struct can lead to mem leaks when a new value get set and the old one is not freed.

char * old_extranonce_str = GLOBAL_STATE->extranonce_str;
GLOBAL_STATE->extranonce_str = stratum_api_v1_message.extranonce_str;
GLOBAL_STATE->extranonce_2_len = stratum_api_v1_message.extranonce_2_len;
free(old_extranonce_str);

like this
this makes sure that every struct with extern flag can exists only once.
i can also move the structs into own headers, then they can get included as needed

@johnny9
Copy link
Collaborator
johnny9 commented Jul 12, 2025

the thing is that the GLOBAL_STATE is static in main but not accessible without routing it through methods, in fact its static^^ other thing is that everything that is stored in that pointer struct can lead to mem leaks when a new value get set and the old one is not freed.

Ok, this might be worthwhile and I might agree, but you called the PR splitt modules but there wasn't any change in dependencies. You need to work on the commit and PR clarity here. It changes 1000 lines of code. Lets be clearer on the intent

#include "asic.h"
#include "device_config.h"
#include "power_management_task.h"
Copy link
Collaborator
@johnny9 johnny9 Jul 12, 2025

Choose a reason for hiding this comment

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

damn this sucks. I know you didn't cause the problem and this change is just exposing it more but asic shouldnt care at all about the tasks that are leveraging it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there will more come up. its not the first time im doing such things^^

@johnny9
Copy link
Collaborator
johnny9 commented Jul 12, 2025

other thing is that everything that is stored in that pointer struct can lead to mem leaks when a new value get set and the old one is not freed.

char * old_extranonce_str = GLOBAL_STATE->extranonce_str;
GLOBAL_STATE->extranonce_str = stratum_api_v1_message.extranonce_str;
GLOBAL_STATE->extranonce_2_len = stratum_api_v1_message.extranonce_2_len;
free(old_extranonce_str);

like this

Not everything in the struct will cause memory leaks. Only the alloc'd values like the strings. That is unavoidable. we need to free the dynamically allocated strings regardless of if GLOBAL_STATE holds the pointer or some other module.

@KillerInk
Copy link
Contributor Author
KillerInk commented Jul 12, 2025

other thing is that everything that is stored in that pointer struct can lead to mem leaks when a new value get set and the old one is not freed.

char * old_extranonce_str = GLOBAL_STATE->extranonce_str;
GLOBAL_STATE->extranonce_str = stratum_api_v1_message.extranonce_str;
GLOBAL_STATE->extranonce_2_len = stratum_api_v1_message.extranonce_2_len;
free(old_extranonce_str);

like this

Not everything in the struct will cause memory leaks. Only the alloc'd values like the strings. That is unavoidable. we need to free the dynamically allocated strings regardless of if GLOBAL_STATE holds the pointer or some other module.

i did not say it will, it can. but its now more safe because its using the same memory location and make the free obsolete.
on my side i never noted that leak^^

the thing is that the GLOBAL_STATE is static in main but not accessible without routing it through methods, in fact its static^^ other thing is that everything that is stored in that pointer struct can lead to mem leaks when a new value get set and the old one is not freed.

Ok, this might be worthwhile and I might agree, but you called the PR splitt modules but there wasn't any change in dependencies. You need to work on the commit and PR clarity here. It changes 1000 lines of code. Lets be clearer on the intent

I probably have to, if you have a good title feel free to change it

@KillerInk KillerInk marked this pull request as draft July 12, 2025 08:51
@KillerInk KillerInk changed the title splitt modules. Refactor ASIC Initialization, Frequency Management, and Remove Global State Jul 15, 2025
@KillerInk KillerInk marked this pull request as ready for review July 15, 2025 11:18
@johnny9
Copy link
Collaborator
johnny9 commented Jul 15, 2025

Concept ACK.

This is starting to look much better. I'll make an effort to test this out this week and do a more thorough review.

@KillerInk
Copy link
Contributor Author
KillerInk commented Jul 16, 2025

Take your time. i dont expect this get merged soon^^
i realy tried to move the modules into a "modules" folder. but no idea why esp idf dont like header only folders.

# Conflicts:
#	main/http_server/http_server.c
#	main/tasks/power_management_task.c
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
0