diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/jobs.c | 32 | ||||
| -rw-r--r-- | src/queue.c | 2 | ||||
| -rw-r--r-- | src/solver_conformity.c | 12 | ||||
| -rw-r--r-- | src/solver_highs.c | 9 | ||||
| -rw-r--r-- | src/solver_sjf.c | 5 | 
5 files changed, 48 insertions, 12 deletions
@@ -64,6 +64,10 @@ static char *drv_path_to_pname(char *drv_path)  	if (p != NULL)  		*p = '\0'; +	p = strstr(pname, ".drv"); +	if (p != NULL) +		*p = '\0'; +  	return pname;  } @@ -151,11 +155,14 @@ int job_parents_list_insert(struct job *job, struct job *parent)  	return 0;  } -static int job_cost_estimate(struct job *job) +int job_cost(struct job *job)  {  	int ret;  	char *pname; +	if (!evanix_opts.max_time) +		return 1; +  	pname = drv_path_to_pname(job->drv_path);  	if (pname == NULL) {  		print_err("Unable to obtain pname from drv_path: %s", @@ -163,6 +170,12 @@ static int job_cost_estimate(struct job *job)  		return -EINVAL;  	} +	ret = sqlite3_reset(evanix_opts.estimate.statement); +	if (ret != SQLITE_OK) { +		print_err("%s", "Failed to reset sql statement"); +		ret = -EPERM; +		goto out_free_pname; +	}  	ret = sqlite3_bind_text(evanix_opts.estimate.statement, 1, pname, -1,  				NULL);  	if (ret != SQLITE_OK) { @@ -173,10 +186,10 @@ static int job_cost_estimate(struct job *job)  	ret = sqlite3_step(evanix_opts.estimate.statement);  	if (ret == SQLITE_DONE) { +		print_err("Failed to acquire statistics for %s", pname);  		ret = -ENOENT;  		goto out_free_pname; -	} -	if (ret != SQLITE_ROW) { +	} else if (ret != SQLITE_ROW) {  		print_err("%s", "Failed to step sql");  		ret = -EPERM;  		goto out_free_pname; @@ -192,13 +205,22 @@ out_free_pname:  int job_cost_recursive(struct job *job)  { -	int32_t builds = 1; +	int ret, builds; + +	ret = job_cost(job); +	if (ret < 0) +		return ret; +	builds = ret;  	for (size_t i = 0; i < job->deps_filled; i++) {  		if (job->deps[i]->insubstituters)  			continue; -		builds++; +		ret = job_cost(job->deps[i]); +		if (ret < 0) +			return ret; + +		builds += ret;  	}  	return builds; diff --git a/src/queue.c b/src/queue.c index 2474a39..e74edf2 100644 --- a/src/queue.c +++ b/src/queue.c @@ -102,7 +102,7 @@ int queue_pop(struct queue *queue, struct job **job)  	}  	pthread_mutex_lock(&queue->mutex); -	if (evanix_opts.max_builds) { +	if (evanix_opts.max_builds || evanix_opts.max_time) {  		ret = evanix_opts.solver(&j, &queue->jobs, queue->resources);  		if (ret < 0)  			goto out_mutex_unlock; diff --git a/src/solver_conformity.c b/src/solver_conformity.c index d2b2d82..882d717 100644 --- a/src/solver_conformity.c +++ b/src/solver_conformity.c @@ -39,18 +39,24 @@ int solver_conformity(struct job **job, struct job_clist *q, int32_t resources)  {  	struct job *j;  	float conformity_cur; +	int ret;  	struct job *selected = NULL;  	float conformity_max = -1;  	CIRCLEQ_FOREACH (j, q, clist) { -		if (j->stale) { +		if (j->stale)  			continue; -		} else if (job_cost_recursive(j) > resources) { + +		ret = job_cost_recursive(j); +		if (ret < 0) +			return ret; + +		if (ret > resources) {  			job_stale_set(j);  			if (evanix_opts.solver_report) {  				printf("❌ refusing to build %s, cost: %d\n", -				       j->drv_path, job_cost_recursive(j)); +				       j->drv_path, ret);  			}  		}  	} diff --git a/src/solver_highs.c b/src/solver_highs.c index 0e8b0cb..e3b6a1f 100644 --- a/src/solver_highs.c +++ b/src/solver_highs.c @@ -89,8 +89,13 @@ static int solver_highs_unwrapped(double *solution, struct job_clist *q,  		ret = -errno;  		goto out_free_col_profit;  	} -	for (size_t i = 0; i < jobid->filled; i++) -		constraint_value[i] = 1.0; +	for (size_t i = 0; i < jobid->filled; i++) { +		ret = job_cost(jobid->jobs[i]); +		if (ret < 0) +			return ret; + +		constraint_value[i] = ret; +	}  	ret = Highs_addRow(highs, 0, resources, jobid->filled, constraint_index,  			   constraint_value); diff --git a/src/solver_sjf.c b/src/solver_sjf.c index c81f718..4cbdbc1 100644 --- a/src/solver_sjf.c +++ b/src/solver_sjf.c @@ -18,11 +18,14 @@ int solver_sjf(struct job **job, struct job_clist *q, int32_t resources)  			continue;  		cost_cur = job_cost_recursive(j); +		if (cost_cur < 0) +			return cost_cur; +  		if (cost_cur > resources) {  			job_stale_set(j);  			if (evanix_opts.solver_report) {  				printf("❌ refusing to build %s, cost: %d\n", -				       j->drv_path, job_cost_recursive(j)); +				       j->drv_path, cost_cur);  			}  		}  | 
