Changeset 71eef11 in mainline for kernel/generic


Ignore:
Timestamp:
2008-02-06T14:24:13Z (17 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7208b6c
Parents:
1b067315
Message:

remove config.memory_size, get_memory_size() and memory_init.{c|d}
the amount of available memory can be calculated from the sizes of the zones
add FRAMES2SIZE, SIZE2KB and SIZE2MB functions/macros (code readability)

Location:
kernel/generic
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/config.h

    r1b067315 r71eef11  
    7070
    7171        uintptr_t base;
    72         size_t memory_size;             /**< Size of detected memory in bytes. */
    7372        size_t kernel_size;             /**< Size of memory in bytes taken by kernel and stack */
    7473       
  • kernel/generic/include/macros.h

    r1b067315 r71eef11  
    6767#define PA_overlaps(x, szx, y, szy)     overlaps(KA2PA(x), szx, KA2PA(y), szy)
    6868
     69#define SIZE2KB(size) (size >> 10)
     70#define SIZE2MB(size) (size >> 20)
     71
    6972#define STRING(arg) STRING_ARG(arg)
    7073#define STRING_ARG(arg) #arg
  • kernel/generic/include/mm/frame.h

    r1b067315 r71eef11  
    8585}
    8686
     87static inline size_t FRAMES2SIZE(count_t frames)
     88{
     89        return (size_t) (frames << FRAME_WIDTH);
     90}
     91
    8792#define IS_BUDDY_ORDER_OK(index, order)         \
    8893        ((~(((unative_t) -1) << (order)) & (index)) == 0)
     
    105110
    106111extern int zone_create(pfn_t start, count_t count, pfn_t confframe, int flags);
    107 void *frame_get_parent(pfn_t frame, unsigned int hint);
    108 void frame_set_parent(pfn_t frame, void *data, unsigned int hint);
    109 void frame_mark_unavailable(pfn_t start, count_t count);
    110 uintptr_t zone_conf_size(count_t count);
    111 void zone_merge(unsigned int z1, unsigned int z2);
    112 void zone_merge_all(void);
     112extern void *frame_get_parent(pfn_t frame, unsigned int hint);
     113extern void frame_set_parent(pfn_t frame, void *data, unsigned int hint);
     114extern void frame_mark_unavailable(pfn_t start, count_t count);
     115extern uintptr_t zone_conf_size(count_t count);
     116extern void zone_merge(unsigned int z1, unsigned int z2);
     117extern void zone_merge_all(void);
     118extern uint64_t zone_total_size(void);
    113119
    114120/*
     
    116122 */
    117123extern void zone_print_list(void);
    118 void zone_print_one(unsigned int znum);
     124extern void zone_print_one(unsigned int znum);
    119125
    120126#endif
  • kernel/generic/src/main/main.c

    r1b067315 r71eef11  
    6464#include <align.h>
    6565#include <interrupt.h>
    66 #include <arch/mm/memory_init.h>
    6766#include <mm/frame.h>
    6867#include <mm/page.h>
     
    144143       
    145144        config.base = hardcoded_load_address;
    146         config.memory_size = get_memory_size();
    147        
    148145        config.kernel_size = ALIGN_UP(hardcoded_ktext_size +
    149146            hardcoded_kdata_size, PAGE_SIZE);
     
    220217        ddi_init();
    221218        arch_post_mm_init();
    222 
     219       
    223220        version_print();
    224         printf("kernel: %.*p hardcoded_ktext_size=%zdK, "
    225             "hardcoded_kdata_size=%zdK\n", sizeof(uintptr_t) * 2,
    226             config.base, hardcoded_ktext_size >> 10,
    227             hardcoded_kdata_size >> 10);
    228         printf("stack:  %.*p size=%zdK\n", sizeof(uintptr_t) * 2,
    229             config.stack_base, config.stack_size >> 10);
    230 
     221        printf("kernel: %.*p hardcoded_ktext_size=%zd KB, "
     222            "hardcoded_kdata_size=%zd KB\n", sizeof(uintptr_t) * 2,
     223                config.base, SIZE2KB(hardcoded_ktext_size),
     224                SIZE2KB(hardcoded_kdata_size));
     225        printf("stack:  %.*p size=%zd KB\n", sizeof(uintptr_t) * 2,
     226            config.stack_base, SIZE2KB(config.stack_size));
     227       
    231228        arch_pre_smp_init();
    232229        smp_init();
    233230        /* Slab must be initialized after we know the number of processors. */
    234231        slab_enable_cpucache();
    235 
    236         printf("config.memory_size=%zdM\n", config.memory_size >> 20);
    237         printf("config.cpu_count=%zd\n", config.cpu_count);
     232       
     233        printf("Detected %zu CPU(s), %llu MB free memory\n",
     234                config.cpu_count, SIZE2MB(zone_total_size()));
    238235        cpu_init();
    239236       
  • kernel/generic/src/mm/frame.c

    r1b067315 r71eef11  
    105105
    106106
    107 /*********************************/
     107/********************/
    108108/* Helper functions */
     109/********************/
     110
    109111static inline index_t frame_index(zone_t *zone, frame_t *frame)
    110112{
    111         return (index_t)(frame - zone->frames);
    112 }
     113        return (index_t) (frame - zone->frames);
     114}
     115
    113116static inline index_t frame_index_abs(zone_t *zone, frame_t *frame)
    114117{
    115         return (index_t)(frame - zone->frames) + zone->base;
    116 }
     118        return (index_t) (frame - zone->frames) + zone->base;
     119}
     120
    117121static inline int frame_index_valid(zone_t *zone, index_t index)
    118122{
    119         return index >= 0 && index < zone->count;
     123        return (index >= 0) && (index < zone->count);
    120124}
    121125
     
    123127static index_t make_frame_index(zone_t *zone, frame_t *frame)
    124128{
    125         return frame - zone->frames;
     129        return (frame - zone->frames);
    126130}
    127131
     
    138142}
    139143
    140 /*************************************/
     144/**********************/
    141145/* Zoneinfo functions */
     146/**********************/
    142147
    143148/**
     
    155160        ipl = interrupts_disable();
    156161        spinlock_lock(&zones.lock);
     162       
    157163        /* Try to merge */
    158         if (zones.count + 1 == ZONES_MAX)
    159                 panic("Maximum zone(%d) count exceeded.", ZONES_MAX);
     164        if (zones.count + 1 == ZONES_MAX) {
     165                printf("Maximum zone count %u exceeded!\n", ZONES_MAX);
     166                spinlock_unlock(&zones.lock);
     167                interrupts_restore(ipl);
     168                return -1;
     169        }
     170       
    160171        for (i = 0; i < zones.count; i++) {
    161172                /* Check for overflow */
    162173                z = zones.info[i];
    163                 if (overlaps(newzone->base,newzone->count, z->base,
    164                     z->count)) {
     174                if (overlaps(newzone->base, newzone->count, z->base, z->count)) {
    165175                        printf("Zones overlap!\n");
    166176                        return -1;
     
    169179                        break;
    170180        }
     181       
    171182        /* Move other zones up */
    172183        for (j = i; j < zones.count; j++)
    173184                zones.info[j + 1] = zones.info[j];
     185       
    174186        zones.info[i] = newzone;
    175187        zones.count++;
     188       
    176189        spinlock_unlock(&zones.lock);
    177190        interrupts_restore(ipl);
     
    182195/**
    183196 * Try to find a zone where can we find the frame
    184  
     197 *
    185198 * Assume interrupts are disabled.
    186  
     199 *
    187200 * @param frame Frame number contained in zone
    188201 * @param pzone If not null, it is used as zone hint. Zone index
     
    901914        }
    902915
    903         z = (zone_t *)PA2KA(PFN2ADDR(confframe));
     916        z = (zone_t *) PA2KA(PFN2ADDR(confframe));
    904917        zone_construct(start, count, z, flags);
    905918        znum = zones_add_zone(z);
     
    11101123
    11111124
     1125/** Return total size of all zones
     1126 *
     1127 */
     1128uint64_t zone_total_size(void) {
     1129        zone_t *zone = NULL;
     1130        unsigned int i;
     1131        ipl_t ipl;
     1132        uint64_t total = 0;
     1133
     1134        ipl = interrupts_disable();
     1135        spinlock_lock(&zones.lock);
     1136       
     1137        for (i = 0; i < zones.count; i++) {
     1138                zone = zones.info[i];
     1139                spinlock_lock(&zone->lock);
     1140                total += (uint64_t) FRAMES2SIZE(zone->count);
     1141                spinlock_unlock(&zone->lock);
     1142        }
     1143       
     1144        spinlock_unlock(&zones.lock);
     1145        interrupts_restore(ipl);
     1146       
     1147        return total;
     1148}
     1149
     1150
    11121151
    11131152/** Prints list of zones
     
    11611200
    11621201        for (i = 0; i < zones.count; i++) {
    1163                 if (i == num || PFN2ADDR(zones.info[i]->base) == num) {
     1202                if ((i == num) || (PFN2ADDR(zones.info[i]->base) == num)) {
    11641203                        zone = zones.info[i];
    11651204                        break;
     
    11751214        printf("Zone base address: %#.*p\n", sizeof(uintptr_t) * 2,
    11761215            PFN2ADDR(zone->base));
    1177         printf("Zone size: %zd frames (%zdK)\n", zone->count,
    1178             ((zone->count) * FRAME_SIZE) >> 10);
    1179         printf("Allocated space: %zd frames (%zdK)\n", zone->busy_count,
    1180             (zone->busy_count * FRAME_SIZE) >> 10);
    1181         printf("Available space: %zd frames (%zdK)\n", zone->free_count,
    1182             (zone->free_count * FRAME_SIZE) >> 10);
     1216        printf("Zone size: %zd frames (%zd KB)\n", zone->count,
     1217                SIZE2KB(FRAMES2SIZE(zone->count)));
     1218        printf("Allocated space: %zd frames (%zd KB)\n", zone->busy_count,
     1219                SIZE2KB(FRAMES2SIZE(zone->busy_count)));
     1220        printf("Available space: %zd frames (%zd KB)\n", zone->free_count,
     1221                SIZE2KB(FRAMES2SIZE(zone->free_count)));
    11831222        buddy_system_structure_print(zone->buddy_system, FRAME_SIZE);
    1184        
    11851223        spinlock_unlock(&zone->lock);
     1224       
    11861225out:
    11871226        spinlock_unlock(&zones.lock);
Note: See TracChangeset for help on using the changeset viewer.