Changeset 6119f24 in mainline


Ignore:
Timestamp:
2011-01-29T18:58:24Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
10477601, 6aef742
Parents:
d7533c7
Message:

map klog area and clock page directly in tasks which require them (do not use the memory sharing from naming service via IPC)
this avoids the circular dependency between gettimeofday() and the async framework (as reported by Jakub Jermar)
it also simplifies the code of the naming service (the memory sharing was never strictly necessary, it was only a demonstrator)

Location:
uspace
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/klog/klog.c

    rd7533c7 r6119f24  
    3636
    3737#include <stdio.h>
    38 #include <ipc/ns.h>
    3938#include <async.h>
    40 #include <ipc/services.h>
    4139#include <as.h>
    42 #include <sysinfo.h>
     40#include <ddi.h>
    4341#include <event.h>
    4442#include <errno.h>
    4543#include <str_error.h>
    4644#include <io/klog.h>
     45#include <sysinfo.h>
    4746
    4847#define NAME       "klog"
     
    7978int main(int argc, char *argv[])
    8079{
    81         klog = service_klog_share_in(&klog_length);
    82         if (klog == NULL) {
    83                 printf("%s: Error accessing to klog\n", NAME);
    84                 return -1;
     80        size_t pages;
     81        int rc = sysinfo_get_value("klog.pages", &pages);
     82        if (rc != EOK) {
     83                fprintf(stderr, "%s: Unable to get number of klog pages\n",
     84                    NAME);
     85                return rc;
    8586        }
    8687       
    87         if (event_subscribe(EVENT_KLOG, 0) != EOK) {
    88                 printf("%s: Error registering klog notifications\n", NAME);
    89                 return -1;
     88        uintptr_t faddr;
     89        rc = sysinfo_get_value("klog.faddr", &faddr);
     90        if (rc != EOK) {
     91                fprintf(stderr, "%s: Unable to get klog physical address\n",
     92                    NAME);
     93                return rc;
     94        }
     95       
     96        size_t size = pages * PAGE_SIZE;
     97        klog_length = size / sizeof(wchar_t);
     98       
     99        klog = (wchar_t *) as_get_mappable_page(size);
     100        if (klog == NULL) {
     101                fprintf(stderr, "%s: Unable to allocate virtual memory area\n",
     102                    NAME);
     103                return ENOMEM;
     104        }
     105       
     106        rc = physmem_map((void *) faddr, (void *) klog, pages,
     107            AS_AREA_READ | AS_AREA_CACHEABLE);
     108        if (rc != EOK) {
     109                fprintf(stderr, "%s: Unable to map klog\n", NAME);
     110                return rc;
     111        }
     112       
     113        rc = event_subscribe(EVENT_KLOG, 0);
     114        if (rc != EOK) {
     115                fprintf(stderr, "%s: Unable to register klog notifications\n",
     116                    NAME);
     117                return rc;
    90118        }
    91119       
  • uspace/lib/c/generic/ipc/ns.c

    rd7533c7 r6119f24  
    3434
    3535#include <async.h>
    36 #include <ipc/services.h>
    3736#include <ipc/ns.h>
    38 #include <sysinfo.h>
    39 #include <errno.h>
    40 #include <as.h>
    41 #include <macros.h>
    4237
    4338int service_register(sysarg_t service)
     
    5651}
    5752
    58 wchar_t *service_klog_share_in(size_t *length)
    59 {
    60         size_t pages;
    61         if (sysinfo_get_value("klog.pages", &pages) != EOK)
    62                 return NULL;
    63        
    64         size_t size = pages * PAGE_SIZE;
    65         *length = size / sizeof(wchar_t);
    66        
    67         wchar_t *klog = (wchar_t *) as_get_mappable_page(size);
    68         if (klog == NULL)
    69                 return NULL;
    70        
    71         int res = async_share_in_start_1_0(PHONE_NS, (void *) klog, size,
    72             SERVICE_MEM_KLOG);
    73         if (res != EOK) {
    74                 as_area_destroy((void *) klog);
    75                 return NULL;
    76         }
    77        
    78         return klog;
    79 }
    80 
    81 void *service_realtime_share_in(void)
    82 {
    83         void *rtime = as_get_mappable_page(PAGE_SIZE);
    84         if (rtime == NULL)
    85                 return NULL;
    86        
    87         int res = async_share_in_start_1_0(PHONE_NS, rtime, PAGE_SIZE,
    88             SERVICE_MEM_REALTIME);
    89         if (res != EOK) {
    90                 as_area_destroy((void *) rtime);
    91                 return NULL;
    92         }
    93        
    94         return rtime;
    95 }
    96 
    9753/** @}
    9854 */
  • uspace/lib/c/generic/time.c

    rd7533c7 r6119f24  
    3434
    3535#include <sys/time.h>
    36 #include <unistd.h>
     36#include <time.h>
    3737#include <bool.h>
    38 #include <ipc/ns.h>
    3938#include <arch/barrier.h>
    4039#include <macros.h>
     40#include <errno.h>
     41#include <sysinfo.h>
     42#include <as.h>
     43#include <ddi.h>
    4144#include <libc.h>
    42 #include <time.h>
    4345
    4446/** Pointer to kernel shared variables with time */
     
    137139int gettimeofday(struct timeval *tv, struct timezone *tz)
    138140{
    139         if (!ktime) {
    140                 ktime = service_realtime_share_in();
    141                 if (!ktime)
     141        if (ktime == NULL) {
     142                uintptr_t faddr;
     143                int rc = sysinfo_get_value("clock.faddr", &faddr);
     144                if (rc != EOK) {
     145                        errno = rc;
    142146                        return -1;
     147                }
     148               
     149                void *addr = as_get_mappable_page(PAGE_SIZE);
     150                if (addr == NULL) {
     151                        errno = ENOMEM;
     152                        return -1;
     153                }
     154               
     155                rc = physmem_map((void *) faddr, addr, 1,
     156                    AS_AREA_READ | AS_AREA_CACHEABLE);
     157                if (rc != EOK) {
     158                        as_area_destroy(addr);
     159                        errno = rc;
     160                        return -1;
     161                }
     162               
     163                ktime = addr;
    143164        }
    144165       
  • uspace/lib/c/include/ipc/ns.h

    rd7533c7 r6119f24  
    5050extern int service_connect_blocking(sysarg_t, sysarg_t, sysarg_t);
    5151
    52 extern wchar_t *service_klog_share_in(size_t *);
    53 extern void *service_realtime_share_in(void);
    54 
    5552#endif
    5653
  • uspace/lib/c/include/ipc/services.h

    rd7533c7 r6119f24  
    6666} services_t;
    6767
    68 /* Memory areas to be received from NS */
    69 typedef enum {
    70         SERVICE_MEM_REALTIME = 1,
    71         SERVICE_MEM_KLOG = 2
    72 } mem_services_t;
    73 
    7468#endif
    7569
  • uspace/srv/ns/ns.c

    rd7533c7 r6119f24  
    3737
    3838#include <ipc/ipc.h>
    39 #include <ipc/services.h>
    4039#include <ipc/ns.h>
    41 #include <unistd.h>
    4240#include <stdio.h>
    4341#include <errno.h>
    44 #include <as.h>
    45 #include <ddi.h>
    46 #include <event.h>
    4742#include <macros.h>
    48 #include <sysinfo.h>
    4943#include "ns.h"
    5044#include "service.h"
    5145#include "clonable.h"
    5246#include "task.h"
    53 
    54 static void *clockaddr = NULL;
    55 static void *klogaddr = NULL;
    56 
    57 static void get_as_area(ipc_callid_t callid, ipc_call_t *call, void *faddr,
    58     size_t pages, void **addr)
    59 {
    60         if ((faddr == NULL) || (pages == 0)) {
    61                 ipc_answer_0(callid, ENOENT);
    62                 return;
    63         }
    64        
    65         if (*addr == NULL) {
    66                 *addr = as_get_mappable_page(pages * PAGE_SIZE);
    67                
    68                 if (*addr == NULL) {
    69                         ipc_answer_0(callid, ENOENT);
    70                         return;
    71                 }
    72                
    73                 if (physmem_map(faddr, *addr, pages,
    74                     AS_AREA_READ | AS_AREA_CACHEABLE) != 0) {
    75                         ipc_answer_0(callid, ENOENT);
    76                         return;
    77                 }
    78         }
    79        
    80         ipc_answer_2(callid, EOK, (sysarg_t) *addr, AS_AREA_READ);
    81 }
    82 
    83 static void setup_clock_area(ipc_callid_t callid, ipc_call_t *call, void **addr)
    84 {
    85         uintptr_t faddr;
    86         int err = sysinfo_get_value("clock.faddr", &faddr);
    87        
    88         if (err != EOK)
    89                 ipc_answer_0(callid, err);
    90        
    91         get_as_area(callid, call, (void *) faddr, 1, addr);
    92 }
    93 
    94 static void setup_klog_area(ipc_callid_t callid, ipc_call_t *call, void **addr)
    95 {
    96         uintptr_t faddr;
    97         int err = sysinfo_get_value("klog.faddr", &faddr);
    98        
    99         if (err != EOK)
    100                 ipc_answer_0(callid, err);
    101        
    102         size_t pages;
    103         err = sysinfo_get_value("klog.pages", &pages);
    104        
    105         if (err != EOK)
    106                 ipc_answer_0(callid, err);
    107        
    108         get_as_area(callid, call, (void *) faddr, pages, addr);
    109 }
    11047
    11148int main(int argc, char **argv)
     
    13875               
    13976                switch (IPC_GET_IMETHOD(call)) {
    140                 case IPC_M_SHARE_IN:
    141                         switch (IPC_GET_ARG3(call)) {
    142                         case SERVICE_MEM_REALTIME:
    143                                 setup_clock_area(callid, &call, &clockaddr);
    144                                 break;
    145                         case SERVICE_MEM_KLOG:
    146                                 setup_klog_area(callid, &call, &klogaddr);
    147                                 break;
    148                         default:
    149                                 ipc_answer_0(callid, ENOENT);
    150                         }
    151                         continue;
    15277                case IPC_M_PHONE_HUNGUP:
    15378                        retval = ns_task_disconnect(&call);
  • uspace/srv/ns/task.h

    rd7533c7 r6119f24  
    3535
    3636#include <ipc/common.h>
     37#include <task.h>
    3738
    3839extern int task_init(void);
Note: See TracChangeset for help on using the changeset viewer.