Changeset de9460e in mainline
- Timestamp:
- 2009-11-21T10:38:16Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 01607604
- Parents:
- 4e739652 (diff), fd1210a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- kernel/generic
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/ipc/ipc.h
r4e739652 rde9460e 51 51 /** This is answer to a call */ 52 52 #define IPC_CALL_ANSWERED (1 << 0) 53 /** This call will not be freed on error */54 #define IPC_CALL_STATIC_ALLOC (1 << 1)55 53 /** Answer will not be passed to userspace, will be discarded */ 56 #define IPC_CALL_DISCARD_ANSWER (1 << 2)54 #define IPC_CALL_DISCARD_ANSWER (1 << 1) 57 55 /** Call was forwarded */ 58 #define IPC_CALL_FORWARDED (1 << 3)56 #define IPC_CALL_FORWARDED (1 << 2) 59 57 /** Identify connect_me_to answer */ 60 #define IPC_CALL_CONN_ME_TO (1 << 4)58 #define IPC_CALL_CONN_ME_TO (1 << 3) 61 59 /** Interrupt notification */ 62 #define IPC_CALL_NOTIF (1 << 5)60 #define IPC_CALL_NOTIF (1 << 4) 63 61 64 62 /* … … 267 265 waitq_t wq; 268 266 267 /** Linkage for the list of task's synchronous answerboxes. */ 268 link_t sync_box_link; 269 269 270 /** Phones connected to this answerbox. */ 270 271 link_t connected_phones; … … 316 317 } call_t; 317 318 319 320 extern answerbox_t *ipc_phone_0; 321 322 318 323 extern void ipc_init(void); 319 extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, int); 320 extern void ipc_answer(answerbox_t *, call_t *); 324 325 extern call_t * ipc_call_alloc(int); 326 extern void ipc_call_free(call_t *); 327 321 328 extern int ipc_call(phone_t *, call_t *); 322 329 extern int ipc_call_sync(phone_t *, call_t *); 330 extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, int); 331 extern int ipc_forward(call_t *, phone_t *, answerbox_t *, int); 332 extern void ipc_answer(answerbox_t *, call_t *); 333 323 334 extern void ipc_phone_init(phone_t *); 324 335 extern void ipc_phone_connect(phone_t *, answerbox_t *); 325 extern void ipc_call_free(call_t *);326 extern call_t * ipc_call_alloc(int); 336 extern int ipc_phone_hangup(phone_t *); 337 327 338 extern void ipc_answerbox_init(answerbox_t *, struct task *); 328 extern void ipc_call_static_init(call_t *); 329 extern void task_print_list(void); 330 extern int ipc_forward(call_t *, phone_t *, answerbox_t *, int); 339 331 340 extern void ipc_cleanup(void); 332 extern int ipc_phone_hangup(phone_t *);333 341 extern void ipc_backsend_err(phone_t *, call_t *, unative_t); 334 extern void ipc_print_task(task_id_t);335 342 extern void ipc_answerbox_slam_phones(answerbox_t *, bool); 336 343 extern void ipc_cleanup_call_list(link_t *); 337 344 338 extern answerbox_t *ipc_phone_0;345 extern void ipc_print_task(task_id_t); 339 346 340 347 #endif -
kernel/generic/include/proc/task.h
r4e739652 rde9460e 98 98 */ 99 99 atomic_t active_calls; 100 /** List of synchronous answerboxes. */ 101 link_t sync_box_head; 100 102 101 103 #ifdef CONFIG_UDEBUG … … 132 134 extern int task_kill(task_id_t id); 133 135 extern uint64_t task_get_accounting(task_t *t); 136 extern void task_print_list(void); 134 137 135 138 extern void cap_set(task_t *t, cap_t caps); -
kernel/generic/src/ipc/ipc.c
r4e739652 rde9460e 62 62 63 63 static slab_cache_t *ipc_call_slab; 64 static slab_cache_t *ipc_answerbox_slab; 64 65 65 66 /** Initialize a call structure. … … 96 97 } 97 98 98 /** Initialize a statically allocated call structure.99 *100 * @param call Statically allocated kernel call structure to be101 * initialized.102 */103 void ipc_call_static_init(call_t *call)104 {105 _ipc_call_init(call);106 call->flags |= IPC_CALL_STATIC_ALLOC;107 }108 109 99 /** Deallocate a call structure. 110 100 * … … 113 103 void ipc_call_free(call_t *call) 114 104 { 115 ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));116 105 /* Check to see if we have data in the IPC_M_DATA_SEND buffer. */ 117 106 if (call->buffer) … … 130 119 spinlock_initialize(&box->irq_lock, "ipc_box_irqlock"); 131 120 waitq_initialize(&box->wq); 121 link_initialize(&box->sync_box_link); 132 122 list_initialize(&box->connected_phones); 133 123 list_initialize(&box->calls); … … 179 169 int ipc_call_sync(phone_t *phone, call_t *request) 180 170 { 181 answerbox_t sync_box; 182 183 ipc_answerbox_init(&sync_box, TASK); 171 answerbox_t *sync_box; 172 ipl_t ipl; 173 174 sync_box = slab_alloc(ipc_answerbox_slab, 0); 175 ipc_answerbox_init(sync_box, TASK); 176 177 /* 178 * Put the answerbox on the TASK's list of synchronous answerboxes so 179 * that it can be cleaned up if the call is interrupted. 180 */ 181 ipl = interrupts_disable(); 182 spinlock_lock(&TASK->lock); 183 list_append(&sync_box->sync_box_link, &TASK->sync_box_head); 184 spinlock_unlock(&TASK->lock); 185 interrupts_restore(ipl); 184 186 185 187 /* We will receive data in a special box. */ 186 request->callerbox = &sync_box;188 request->callerbox = sync_box; 187 189 188 190 ipc_call(phone, request); 189 if (!ipc_wait_for_call(&sync_box, SYNCH_NO_TIMEOUT, 190 SYNCH_FLAGS_INTERRUPTIBLE)) 191 if (!ipc_wait_for_call(sync_box, SYNCH_NO_TIMEOUT, 192 SYNCH_FLAGS_INTERRUPTIBLE)) { 193 /* The answerbox and the call will be freed by ipc_cleanup(). */ 191 194 return EINTR; 195 } 196 197 /* 198 * The answer arrived without interruption so we can remove the 199 * answerbox from the TASK's list of synchronous answerboxes. 200 */ 201 (void) interrupts_disable(); 202 spinlock_lock(&TASK->lock); 203 list_remove(&sync_box->sync_box_link); 204 spinlock_unlock(&TASK->lock); 205 interrupts_restore(ipl); 206 207 slab_free(ipc_answerbox_slab, sync_box); 192 208 return EOK; 193 209 } … … 520 536 int i; 521 537 call_t *call; 538 ipl_t ipl; 522 539 523 540 /* Disconnect all our phones ('ipc_phone_hangup') */ … … 545 562 spinlock_unlock(&TASK->answerbox.lock); 546 563 547 /* Wait for all async answers to arrive */ 564 /* Wait for all answers to interrupted synchronous calls to arrive */ 565 ipl = interrupts_disable(); 566 while (!list_empty(&TASK->sync_box_head)) { 567 answerbox_t *box = list_get_instance(TASK->sync_box_head.next, 568 answerbox_t, sync_box_link); 569 570 list_remove(&box->sync_box_link); 571 call = ipc_wait_for_call(box, SYNCH_NO_TIMEOUT, 572 SYNCH_FLAGS_NONE); 573 ipc_call_free(call); 574 slab_free(ipc_answerbox_slab, box); 575 } 576 interrupts_restore(ipl); 577 578 /* Wait for all answers to asynchronous calls to arrive */ 548 579 while (1) { 549 580 /* Go through all phones, until all are FREE... */ … … 574 605 ASSERT((call->flags & IPC_CALL_ANSWERED) || 575 606 (call->flags & IPC_CALL_NOTIF)); 576 ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));577 607 578 608 /* … … 593 623 ipc_call_slab = slab_cache_create("ipc_call", sizeof(call_t), 0, NULL, 594 624 NULL, 0); 625 ipc_answerbox_slab = slab_cache_create("ipc_answerbox", 626 sizeof(answerbox_t), 0, NULL, NULL, 0); 595 627 } 596 628 -
kernel/generic/src/ipc/sysipc.c
r4e739652 rde9460e 531 531 unative_t arg1, unative_t arg2, unative_t arg3, ipc_data_t *data) 532 532 { 533 call_t call;533 call_t *call; 534 534 phone_t *phone; 535 535 int res; … … 538 538 GET_CHECK_PHONE(phone, phoneid, return ENOENT); 539 539 540 ipc_call_static_init(&call);541 IPC_SET_METHOD(call .data, method);542 IPC_SET_ARG1(call .data, arg1);543 IPC_SET_ARG2(call .data, arg2);544 IPC_SET_ARG3(call .data, arg3);540 call = ipc_call_alloc(0); 541 IPC_SET_METHOD(call->data, method); 542 IPC_SET_ARG1(call->data, arg1); 543 IPC_SET_ARG2(call->data, arg2); 544 IPC_SET_ARG3(call->data, arg3); 545 545 /* 546 546 * To achieve deterministic behavior, zero out arguments that are beyond 547 547 * the limits of the fast version. 548 548 */ 549 IPC_SET_ARG4(call .data, 0);550 IPC_SET_ARG5(call .data, 0);551 552 if (!(res = request_preprocess( &call, phone))) {549 IPC_SET_ARG4(call->data, 0); 550 IPC_SET_ARG5(call->data, 0); 551 552 if (!(res = request_preprocess(call, phone))) { 553 553 #ifdef CONFIG_UDEBUG 554 554 udebug_stoppable_begin(); 555 555 #endif 556 rc = ipc_call_sync(phone, &call);556 rc = ipc_call_sync(phone, call); 557 557 #ifdef CONFIG_UDEBUG 558 558 udebug_stoppable_end(); 559 559 #endif 560 if (rc != EOK) 560 if (rc != EOK) { 561 /* The call will be freed by ipc_cleanup(). */ 561 562 return rc; 562 process_answer(&call); 563 } 564 process_answer(call); 563 565 564 566 } else { 565 IPC_SET_RETVAL(call.data, res); 566 } 567 rc = STRUCT_TO_USPACE(&data->args, &call.data.args); 567 IPC_SET_RETVAL(call->data, res); 568 } 569 rc = STRUCT_TO_USPACE(&data->args, &call->data.args); 570 ipc_call_free(call); 568 571 if (rc != 0) 569 572 return rc; … … 584 587 ipc_data_t *reply) 585 588 { 586 call_t call;589 call_t *call; 587 590 phone_t *phone; 588 591 int res; 589 592 int rc; 590 593 591 ipc_call_static_init(&call); 592 rc = copy_from_uspace(&call.data.args, &question->args, 593 sizeof(call.data.args)); 594 if (rc != 0) 594 GET_CHECK_PHONE(phone, phoneid, return ENOENT); 595 596 call = ipc_call_alloc(0); 597 rc = copy_from_uspace(&call->data.args, &question->args, 598 sizeof(call->data.args)); 599 if (rc != 0) { 600 ipc_call_free(call); 595 601 return (unative_t) rc; 596 597 GET_CHECK_PHONE(phone, phoneid, return ENOENT); 598 599 if (!(res = request_preprocess( &call, phone))) {602 } 603 604 605 if (!(res = request_preprocess(call, phone))) { 600 606 #ifdef CONFIG_UDEBUG 601 607 udebug_stoppable_begin(); 602 608 #endif 603 rc = ipc_call_sync(phone, &call);609 rc = ipc_call_sync(phone, call); 604 610 #ifdef CONFIG_UDEBUG 605 611 udebug_stoppable_end(); 606 612 #endif 607 if (rc != EOK) 613 if (rc != EOK) { 614 /* The call will be freed by ipc_cleanup(). */ 608 615 return rc; 609 process_answer(&call); 616 } 617 process_answer(call); 610 618 } else 611 IPC_SET_RETVAL(call.data, res); 612 613 rc = STRUCT_TO_USPACE(&reply->args, &call.data.args); 619 IPC_SET_RETVAL(call->data, res); 620 621 rc = STRUCT_TO_USPACE(&reply->args, &call->data.args); 622 ipc_call_free(call); 614 623 if (rc != 0) 615 624 return rc; … … 991 1000 992 1001 if (call->flags & IPC_CALL_NOTIF) { 993 ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));994 995 1002 /* Set in_phone_hash to the interrupt counter */ 996 1003 call->data.phone = (void *) call->priv; … … 1005 1012 if (call->flags & IPC_CALL_ANSWERED) { 1006 1013 process_answer(call); 1007 1008 ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));1009 1014 1010 1015 if (call->flags & IPC_CALL_DISCARD_ANSWER) { -
kernel/generic/src/proc/task.c
r4e739652 rde9460e 178 178 ipc_phone_connect(&ta->phones[0], ipc_phone_0); 179 179 atomic_set(&ta->active_calls, 0); 180 list_initialize(&ta->sync_box_head); 180 181 181 182 mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
Note:
See TracChangeset
for help on using the changeset viewer.